N
N
NikSIk312019-09-22 12:00:01
Laravel
NikSIk31, 2019-09-22 12:00:01

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

2 answer(s)
Y
Yuri Kulaxyz, 2019-09-22
@Kulaxyz

$notification->save()
Forgot

A
Alex Wells, 2019-09-22
@Alex_Wells

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 question

Ask a Question

731 491 924 answers to any question