Answer the question
In order to leave comments, you need to log in
Laravel notifications not being assigned?
why doesn't this code add the parsed_created_at field to the final notification? .
Everything that is received from the database is returned except for my changes (adding the parsed_created_at field)
namespace App\Events;
use App\Notification;
use Jenssegers\Date\Date;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewNotification implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user_id;
public $notification;
public function __construct($user_id, $notification_id)
{
$this->user_id = $user_id;
$notification = Notification::find($notification_id);
$notification->parsed_created_at = Date::parse($notification['created_at'])->format('d F в H:i');
$this->notification = $notification;
}
public function broadcastOn()
{
return new PrivateChannel('notification.' . $this->user_id);
}
public function broadcastWith()
{
return [
'success' => true,
'notification' => $this->notification
];
}
}
Answer the question
In order to leave comments, you need to log in
Why pass a notification object to broadcastWith()? Give an array of primitives with the necessary data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question