mercredi 29 janvier 2020

Notification Laravel

i want to make notification in laravel using ajax and get data from controller but i don't know why this always said 500 internal server error

this is my ajax

$.ajaxSetup({
  headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});
        $(document).ready(function(){
        // updating the view with notifications using ajax
        function load_unseen_notification(view = '')
        {
         $.ajax({
          url:"notif",
          method:"POST",
          beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
          data:{view:view},
          dataType:"json",
          success:function(data)
          {
           $('.dropdown-menu').html(data.notification);
           if(data.unseen_notification > 0)
           {
            $('.count').html(data.unseen_notification);
           }
          }
         });
        }
        load_unseen_notification();
        setInterval(function(){
         load_unseen_notification();;
        }, 5000);
        });

controller

public function index()
{
    $pengumuman = Pengumuman::select("pengumuman.*")->count('pengumuman.id');
    $data = array(
        'unseen_notification'  => $pengumuman
    );
}

web.php

Route::Post('notif', 'NotifController@index')->name('notif');


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire