I recently added a new feature to my website so that admins are able to view and delete files in storage/app/public/files/uploads
This feature works fine in my local copy but on the live server I keep getting a 419 page expired. I searched around the web and found that the most likely cause is a missing @csrf at the start of my form but I already have this in my code.
<form method="POST" action="{{route('dashboard.uploaddelete', $file)}}">
@csrf
<div class="modal-body">
<p class="font-weight-bold">Are you sure you wish to delete {{$file}}? This action is irreversible!</p>
<input type="hidden" name="filename" value="{{$file}}">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-danger">Delete</button>
<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
</div>
</form>
I have tried clearing artisan cache, routes, views and config but no luck.
Any help would be appreciated, thanks!
2
Answers
This solution has worked for me:
Open the file config/session.php and made some changes:
update the values:
Also check the
storage/
folder have an proper permission.After that open the terminal and run those commands:
Mostly 419 error is thrown when the csrf token is being mismatched.
Firstly, try using the webstie in the incognito window, if it worked
then the issue is with the cache memories.
You can manually view the csrf token:
{{ csrf_token() }}
and checkwhether it matches with the token saved in the session.
You can increase the life time of the session in
config/session.php
file by changing thelifetime value
or change it in the.env
file by using thisSESSION_LIFETIME=120
Check both the form and your site uses HTTPS protocol
Check
.env
config, make sure you have bothSESSION_DOMAIN
andAPP_URL
are same
If you are using AJAX call, then you need to pass the csrf token in the header.