Our system has some scheduled jobs, one of the jobs should run as a user to get authorized. What is the best way to do it?
App\Console\Kernel
schedule has these,.
....
$schedule->job(new EveryMinuteJob)->everyMinute();
$schedule->job(new EveryFiveMinuteJob)->everyFiveMinutes();
....
the EveryMinuteJob is being handled in multiple places which are authorized only for admin role users. So in the EveryMinuteJob, using Auth::login() and ::logout() to run the job as admin as below. Is this the only way or any other best practice to do?
class EveryMinuteJob implements ShouldQueue {
public function handle()
{
..........
Auth::login(User::where('super_admin',true)->first());
..........
Auth::logout();
..........
}
}