检查Laravel时间表上的身份验证

问题描述:

我有这样的时间表

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

告诉我这个错误

在Kernel.php第37行中:

In Kernel.php line 37:

试图获取非对象的属性

当我运行此命令时,再次显示此错误

When I run this command show me this error again

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

我需要进行支票验证.

您无法执行此操作,因为用户未运行计划的命令,因此auth()->user()对象将始终为null.

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

要解决此问题,您可以将用户ID保存在DB中,并在计划的命令执行时获取数据.

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