Как сохраненять уведомления в базе данных в произвольной форме. И не пытаться парсить сериализованное поле data
в таблице notifications
как предлагают создатели Laravel.
namespace App\Notifications\Channels;
use Illuminate\Notifications\Notification;
class CustomDatabaseChannel
{
/**
* @param User $notifiable
* @param Notification $notification
*/
public function send($notifiable, Notification $notification)
{
$data = $notification->toDatabase($notifiable);
try {
$notifiable->routeNotificationFor('database')->create([
'id' => $notification->id,
//custom columns here
'action' => $data['action'],
'title'=> $data['title'],
'subtitle'=> $data['subtitle'] ?? null,
'description' => $data['description'],
'from_name' => $data['from_name'] ?? null,
'type' => get_class($notification),
'read_at' => null,
]);
} catch (\Throwable $t) {
CriticalErrorOccurred::dispatch($t);
}
}
}