Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SerializableClosure error in Laravel - Your serialized closure might have been modified and it's unsafe to be unserialized

Tags:

php

laravel-8

I am getting this error in my domain where I have used laravel v8 for my site. enter image description here

enter image description here

It shows error in line no 52 in index file: enter image description here

Previously my .env file was not reading. As soon as I fixed that error I got this one now. Please help me solve this error.

like image 622
Cherryl Rarewings Avatar asked Sep 30 '20 04:09

Cherryl Rarewings


3 Answers

What solved it for me was running the following in my project folder:

php artisan route:clear

I also ran the below commands before the above command, but the error persisted. It only went away when I did the above. For reference, here are the commands I ran beforehand:

php artisan cache:clear
php artisan config:clear
php artisan view:clear
npm run dev
php artisan key:generate

I also want to note that I am using the following stack:

Laravel v8
Jetstream
Inertia
Vue2
like image 137
Ibrahim Avatar answered Oct 16 '22 12:10

Ibrahim


This issue might occur due to change in APP_KEY value in your .env file.

APP_KEY is used for secure data transmission and Laravel recommends to do that by setting it to a random string.

This APP_KEY is used for

  • Encrypting cookies.
  • Creating the signature for signed URLs and queued closures.
  • Encrypting values using the encrypt() and decrypt() helpers.

A encrypted data can be decrypted if you use the same key which was used while encrypting.

So if possible look for a backup .env file and use the same APP_KEY to resolve it.

like image 33
Dark Knight Avatar answered Oct 16 '22 12:10

Dark Knight


It happened to me when I replaced in production my .env file with the .env from development. It was failing because it had a different APP_KEY, so I had to generate a new APP_KEY on production.

It was solved after run these commands:

php artisan key:generate
php artisan config:cache
php artisan route:cache
php artisan view:cache

Maybe it isn't necessary to clear the views and routes.

like image 29
Luis Rodriguez Avatar answered Oct 16 '22 11:10

Luis Rodriguez