我正在制定任务时间表。流程是,我需要发送通知,以提醒他们的义务。
这是我的console\command\remindDuedate
class remindDuedate extends Command
{
protected $signature = 'remindDuedate:run';
protected $description = 'Command description';
public function __construct()
{
parent::__construct();
}
public function handle()
{
while (true) {
$loanapplications = LoanApplication::where('archive',false)->where('status','=',2)->get();
foreach ($loanapplications as $application) {
$user = $application->user_id;
$date_approval = Carbon::createFromTimestamp(strtotime($application->date_approval));
$duration = $application->loanDuration->num_days;
$duedate_warning = $duration-3;
$reminder_date = $date_approval->addDays($duedate_warning)->toDateString();
$now = Carbon::now('Asia/Manila')->toDateString();
$duedate = Carbon::now('Asia/Manila')->addDays(3)->toDateString();
if($reminder_date == $now) {
$user->notify(new remindDuedateNotif());
}
}
}
}
}php追忆:运行

remindDuedateNotif

为什么我得到“调用一个成员函数的整数通知()”
提前谢谢你!
发布于 2020-01-11 21:08:48
您没有获取用户,因此用户仍然是一个整数,将其设置为这样。
$user = User::find($application->user_id);编辑
如您所见,您的通知以用户作为第一个参数。把它和它一起送去。
$user->notify(new remindDuedateNotif($user));在用户对象上发送和通知并传递它是很奇怪的。您很幸运,因为每个$notifiable参数实际上都是用户,因为它将是您发送它的对象。
因此,从$user中删除__contruct()并在任何地方访问用户,您都可以执行以下操作。
'user_id' => $notifiable->id,发布于 2020-01-11 21:57:52
1)用户模型应具有应报告的特征
照明\通知\应通知
2)您需要在应用程序模型中添加应用程序和用户之间的关系
public function user()
{
return $this->belongsTo(User::class);
}3)通知应用程序用户:
$application->user->notify(new remindDuedateNotif());https://stackoverflow.com/questions/59698525
复制相似问题