Skip to content

Commit

Permalink
Replaced carbon with helper in command and implemented lambda instead…
Browse files Browse the repository at this point in the history
… of function
  • Loading branch information
rexlManu committed Nov 18, 2020
1 parent cbdb30a commit d40a372
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/Commands/AutoCloseCommand.php
Expand Up @@ -3,8 +3,6 @@

namespace RexlManu\LaravelTickets\Commands;


use Carbon\Carbon;
use Illuminate\Console\Command;
use RexlManu\LaravelTickets\Events\TicketCloseEvent;
use RexlManu\LaravelTickets\Models\Ticket;
Expand All @@ -25,25 +23,20 @@ class AutoCloseCommand extends Command
*/
protected $description = 'Close any ticket that has become inactive.';

/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$tickets = Ticket::query()->where('updated_at', '<', Carbon::now()->subDays(config('laravel-tickets.autoclose-days')));
$tickets->update(['state' => 'CLOSED']);
$tickets->get()->each(function ($ticket) {
event(new TicketCloseEvent($ticket));
});
$tickets = Ticket::query()->where(
'updated_at',
'<',
now()->subDays(config('laravel-tickets.autoclose-days'))
);

$tickets->update([ 'state' => 'CLOSED' ]);
$tickets->get()->each(fn(Ticket $ticket) => event(new TicketCloseEvent($ticket)));
}
}

0 comments on commit d40a372

Please sign in to comment.