%PDF- %PDF-
Direktori : /var/www/html/hr/api/app/Console/Commands/ |
Current File : /var/www/html/hr/api/app/Console/Commands/NotifyManagersForTimecardApprovalsCommand.php |
<?php namespace App\Console\Commands; use App\Models\Role; use App\Models\Timecard; use App\Models\User; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class NotifyManagersForTimecardApprovalsCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'notifyManagersForTimecardApprovalsCommand'; /** * The console command description. * * @var string */ protected $description = 'Check for projects that have unapproved timecards and notify managers and admins'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $hasTimecardsToApprove = Timecard::query() ->where('status', Timecard::TO_APPROVE) ->exists(); if ($hasTimecardsToApprove) { $usersToNotify = User::query() ->where(function (Builder $q) { $q->whereHas('roles', function (Builder $r) { $r->where('name', Role::ADMIN); }); $q->orWhereHas('managingProjects', function (Builder $p) { $p->whereHas('timecards', function (Builder $t) { $t->where('status', Timecard::TO_APPROVE); }); }); }) ->get(); foreach ($usersToNotify as $user) { /** @var User $user */ $user->notifyForTimecardApproval(); } } } }