I'm using Laravel 5.7
In my view, list.blade.php I have this (relevant portion shown)
<?php $counter=0; ?>@foreach($items as $item)
<button type="button" class="addButton btn btn-default" onclick="document.getElementById({{$counter}}).submit()">
<i class="fa fa-close"></i>
<form id="{{$counter}}" action="{{ URL::route('list.remove') }}" method="POST" style="display: none;">
<input type="hidden" name="item" value="{{$item->item}}"></input>
@csrf
</form>
<?php $counter++;?>
Relevant controller in web.php:
Route::post('/list/remove', 'listController@removeItem')->name('list.remove')->middleware('auth');
My function in listController.php (currently just a test function):
public function removeItem(){
echo "hello";
}
When you click on the button in the list.blade.php you get sent to a page that says
error 419 Sorry, your session has expired. Please refresh and try again.
php artisan route:list returns:
Put the @csrf tag immediately after the form tag before any other form elements. That will solve your problem.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community