kekekiw123's avatar

Laravel after clearing cache redirect doesnt work

I noticed that during the development of my Laravel app the return redirect() sometimes doesnt work when I try to register or login into my app. I hit the submit button and the page just keeps loading and I can see that chrome says "processing" and keeps spinning, so I have to manually click the browser refresh button in order to get redirected to the account page meaning that the user successfully logged in or registered.

But sometimes it works just fine which is strange.

So today I tried to clear the Laravel cache and browser cache

php artisan cache:clear
php artisan route:clear
php artisan config:clear 
php artisan view:clear 

And do a "empty cache and hard reload" on chrome

After that I tried to register a user, and this time redirect didnt work again.

So I checked telescope to look at the headers and noticed this:

The times redirect doesnt work I can see:

referer: "https://www.mysite.test/login",
origin: "https://www.mysite.test",
host: "www.mysite.test"

And the times when redirect works the headers looks like this:

referer: "https://mysite.test/login",
origin: "https://mysite.test",
host: "mysite.test"

So why is "www" added to the url when I clear the cache and why does adding "www" keeps redirect() from working?

I am running my app through Valet if that matters

0 likes
11 replies
bobbybouwmann's avatar

I don't think this has anything to do with the caching part. The reason it probably worked before is because the working solution was cached. You probably have something wrong in your local setup with Valet or something goes wrong inside your application.

Right now, I don't have enough context for a solution!

laracasts_com's avatar

I had this problem when I was using

php artisan serve

You would need to stop this, and start it again. In other words sometimes you need to restart your web service to make sure your updated config is used.

noticed you mentioned you are using valet, here is what you can do:

valet restart

then try your redirect again

bugsysha's avatar

Also have you tried incognito mode in your browser?

bugsysha's avatar

Search your project for redirects or changes on APP_URL or config values. Also make sure that this is not happening cause of some composer package that you've included. In the end you can always rm -fr vendor and composer install to see if it helps. Restarting your computer is also an option.

kekekiw123's avatar

Ok it seemed the problem was that I had to change domain => '.example.com' in my settings, sometimes the app redirected me between www and without www. And the session was not set over the entire domain

bugsysha's avatar

So is that happening on production or on local?

Please or to participate in this conversation.