In your app/Http/Middleware/VerifyCsrfToken.php, change the tokenMatch() method to this.
/**
* Determine if the session and input CSRF tokens match.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function tokensMatch($request)
{
// If request is an ajax request, then check to see if token matches token provider in
// the header. This way, we can use CSRF protection in ajax requests also.
$token = $request->ajax() ? $request->header('X-CSRF-Token') : $request->input('_token');
return $request->session()->token() == $token;
}
Then in your javascript file (assuming you are using jQuery), do this
// CSRF protection
$.ajaxSetup(
{
headers:
{
'X-CSRF-Token': $('input[name="_token"]').val()
}
});
This will allow us to pass the csrf token as a header with the ajax request. The middleware will check to see if the token matches the header.