I am using laravel's default notification system. The type column of the table gets populated by full class path like "App\Notifications\Upvoted" . I am only filling the data column by myself like this:
public function toDatabase($notifiable)
{
return [
"post" => $this->post,
"user" => Auth::user()
];
}
How can I add custom value for "type" column too.
As I am new to Laravel your help will be greatly appreciated.
You can not do this because the type
Field is following morph rules in the Laravel framework.
If you need to save extra data in Notification Table you can pass in an array and then add as a JSON field in data
field.
For instance you return:
public function toArray($notifiable)
{
return [
'post_id' => $this->post_id,
'user_id' => Auth::user()->id,
];
}
And the result in notifacation data field will be:
{ "post_id": "2", "user_id": "1" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With