36

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.

Dark Knight
  • 6,116
  • 1
  • 15
  • 37
Cherryl Rarewings
  • 618
  • 1
  • 5
  • 13

7 Answers7

82

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
Ibrahim
  • 1,209
  • 1
  • 11
  • 16
  • 3
    This `php artisan route:clear` was the solution for me – Gismo1337 Jul 07 '22 at 08:33
  • I suggest the `php artisan optimize` command that combines the functionality of both the "cache:clear" and "route:clear" commands and perform other useful actions to improve the app's performance. – Denis Francia Karell Aug 13 '23 at 05:53
15

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.

Dark Knight
  • 6,116
  • 1
  • 15
  • 37
  • What if I want to change to a new key? Anyway to clear the previous cached content? – Yan Zhao Feb 14 '21 at 15:06
  • Encrypted data can be stored in cache or databse too. If the concent is such that, you can remove it, you can easily do that but sometimes it can be secrets which are used by your users. In that situation you need a migration from old encryption to the new one. – Dark Knight Feb 15 '21 at 05:46
7

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.

Luis Rodriguez
  • 355
  • 3
  • 7
5

Sometimes php artisan cache:clear doesn't work..

You should remove manually. Example

rm -rf bootstrap/cache/*.php
Murat Çakmak
  • 151
  • 2
  • 7
0

try this command

 composer update
  • 2
    Your answer has been flagged as low quality because of its length. It would be best if you explained your solution and perhaps pasted a link to a reference. – Rohit Gupta Jul 12 '22 at 01:21
0

Yes the error often occurs when a new APP_KEY is generated and the changes are not picked up by the server. I'll advise you run this command in the project root directory after the new key generation.

php artisan optimize

It worked well for me!

-3

In vendor → .env,

change APP_URL to http://localhost.

Obsidian
  • 3,719
  • 8
  • 17
  • 30