check authentication on Laravel schedule

后端 未结 2 1923
挽巷
挽巷 2021-01-20 19:54

I have schedule like this

$schedule->call(function () {
     $mial->getMail(Auth::user()->id);
})->everyMinute();

show me this

2条回答
  •  有刺的猬
    2021-01-20 20:16

    You can't do that because a user doesn't run the scheduled command, so auth()->user() object will always be null.

    To fix this, you can save user ID in DB and fetch the data on scheduled command execution.

提交回复
热议问题