It may be overkill but you can try this:
// Form calling named route with hidden token field added.
<form method="POST" action="{{ route('foo') }}" >
@csrf
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
<input type="text" name="name"/><br/>
<input type="submit" value="Add"/>
</form>
// Named Route
Route::post('/foo', function () {
return 'bar';
})->name('foo');
// Add this within the <head></head>
block:
<meta name="_token" content="{!! csrf_token() !!}" />
I did test it on my local using Homestead on Laravel 5.7 which was was fresh install using Laravel Installer 2.0.1 and it worked. What is your environment?
Theory: I wonder if that has something to do with blade rendering html tags with {{ }}
vs. {!! !!}
on your environment or how you are serving it (eg. php artisan serve
). What makes me think that is line 335
of /vendor/laravel/framework/src/illuminate/Foundation/helpers.php
should render the same line manually typed out above.