Submitting form gives error 419, session expired

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>

</form> <?php $counter++;?>


Relevant controller in web.php:

Route::post('/list/remove', '[email protected]')->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

Arnel Forbes replied 16 hours ago

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

Sign in to participate in this thread!

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