1 回答

TA貢獻(xiàn)1871條經(jīng)驗 獲得超13個贊
您應(yīng)該使用toDatabase或toArray方法來保存任何其他數(shù)據(jù)。另外,您無需更改通知遷移。您應(yīng)該$letter在內(nèi)部構(gòu)造變量DatabaseNotification,例如:
public function saveUser($formdata)
{
$password = $formdata['password'];
$securePassword = Hash::make($password);
$user = User::create(array_merge($formdata, ['password' => $securePassword]));
$admin = User::where('type', 'admin')->first();
// $letter = collect([
// 'title' => $user->name.' New User Registered in your Portal',
// ]);
// This syntax or below.
// Notification::send($admin, new DatabaseNotification($user, $message));
// Make sure you added `use Notifiable` trait in your `User` model
$admin->notify(new DatabaseNotification($user, $message));
return $user;
}
然后在您的toArray或toDatabase方法中:
protected $message;
protected $user;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($message, User $user)
{
$this->message = $message;
$this->user = $user;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'user_id' => $this->user->id,
'message' => $this->message
];
}
最終toArray輸出序列化到表的data列中notifications。
- 1 回答
- 0 關(guān)注
- 251 瀏覽
添加回答
舉報