【发布时间】:2020-09-24 23:46:29
【问题描述】:
我在我的用户和学生 eloquent 上使用一对多的关系。我正在使用 Laravel 的通知向用户发送邮件。
我正在尝试发送邮件,内容是那天出生的人。关系很好,我在学生表中有单独的 user_id 列,该学生创建了该用户。并且在发送邮件时,它应该只发送由经过身份验证的用户创建的人。
但是当我登录时,我得到了错误:preg_split() 期望参数 2 是字符串,给定对象
这是我按日期过滤用户的代码
$user->students()->where('birth_date','=', Carbon::today())
我如何调用 toMail 方法
$user->notify(new BirthdayReminder())(在 LoginController 中经过身份验证)
我的 toMail 方法
public function toMail($notifiable)
{
$user = User::findOrFail(auth()->user()->id);
return (new MailMessage)
->from('admin@site.com')
->line('Hello, '.User::first()->name.'!')
->line('Today is birthday of:')
->line($user->students()->where('birth_date','=', Carbon::today()));
}
这里有什么问题?
【问题讨论】:
-
使用
Carbon::now()->format('Y-m-d')代替Carbon::today(),如果birth_date格式是Y-m-d -
没有解决问题
-
BirthdayReminder中有什么内容以及错误来自哪里(文件名,即使它是供应商文件)? -
BirthdayReminder是我用make:notification创建的通知文件, -
而错误来自
vendor\laravel\framework\src\Illuminate\Notifications\Messages\SimpleMessage