HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /var/www/devs.lapieza.net/app/Http/Livewire/
Upload File :
Current File : /var/www/devs.lapieza.net/app/Http/Livewire/Notifications.php
<?php

namespace App\Http\Livewire;

use Livewire\Component;

class Notifications extends Component
{

    public $count = 10;
    //protected $listeners = ['handleNotification'];
    protected $listeners = ['notificationReceived', 'notificationsMarkedAsRead'];

    public function getListeners()
    {
        return [
            'notificationReceived' => 'notificationReceived',
            'notificationsMarkedAsRead' => 'render',
        ];
    }

    public function readNotification($id)
    {
        auth()->user()->notifications->find($id)->markAsRead();
    }

    public function markAllAsRead()
    {
        if (auth()->check()) {
            auth()->user()->unreadNotifications->markAsRead();
            $this->emit('notificationsMarkedAsRead');
        }
    }

    public function notificationReceived($order)
    {
        //log::info('llega notificaciónes cliente' . json_encode($order, true));
        $this->render();
    }

    public function render()
    {
        #return view('livewire.notifications');
        return view('livewire.notifications', [
            'notifications' => $this->getNotificationsProperty(),
        ]);
    }

    public function getNotificationsProperty()
    {
        return auth()->user()->notifications->take($this->count);
    }
}