lundi 2 mai 2016

Ajax request on click on laravel 5

I try to create a messages system I have create message drop down menu and when the user click on it all messages marked as read for that i create:

Controller method:

public function viewed(Request $request)
{
    if ($request->isMethod('post')) {
        \App\Message::where('destination_id','=',Auth::user()->id)->update(['vu' => '1']);
        return 'done';
    }

}

route to this method:

Route::post('notification',['middleware' => 'auth','uses' =>'IndexController@viewed']);

on click event and ajax:

$('#dLabel').click(function(event) {
    event.preventDefault();
    console.log('geted');
    $.ajax({
      url: '/notification',
      type: 'POST',
      processData: false,
      contentType: false,
      success: function(data){
        console.log('done'+data);
      },
      async: true,
      error: function(data){
        console.log('No');
      }
    });
  });



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/24iLzL2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire