How to Call ajax in Laravel 5
You're going to work on controller or route in laravel 5 with ajax data message. There's a need to get the call to work properly. Csrf token in meta tag is your requirement.
<meta name="csrf-token" content="{{ csrf_token() }}" />
Ajax data post to controller or route in laravel 5.
$('.ViewUserDetail').click(function(){
var userid = $(this).attr('id');
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
$.ajax({
type:'POST',
url:"{{url('view-user-detail')}}",
data: {_token: CSRF_TOKEN,userid:userid},
dataType: 'JSON',
success:function(data){
$('#ViewModalChallan').html(data.success);
$('#ViewModalChallan').modal('show');
}
});
});
Ajax to route call
Route::post('view-user-detail', [
'as' => 'view-user-detail',
'uses' => 'AddUserController@ViewUserDetail'
]);
Now finally controller call
public function ViewUserDetail(Request $request)
{
$userid = $request->userid;
}