Support the ongoing development of Laravel.io →
Forms Blade Session

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++;?>

@endforeach

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:

enter image description here

Last updated 3 years ago.
0

maybe it is about CSRF, try using @csrf in your form

0

Put the @csrf tag immediately after the form tag before any other form elements. That will solve your problem.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.