facing a strange situation in laravel 5.2
The project is hosted on godaddy with shared hosting plan.
I've already defined few routes in routes.php and all are working fine.
Recently I've added 3 more under auth middleware, and now those 3 new routes are not working on server. However they're working fine on my localhost. Triple checked the routes.php on server and the code is there.
Route::get('contact','ContactusController#index');
This url is giving following error :
NotFoundHttpException in RouteCollection.php line 161:
and the url mentioned above / below those lines are working fine.
Any suggestions ?
The OP probably cached his routes using route:cacheon the production server, so any changes will require him to clear the route cache via php artisan route:clear for the new changes to take effect.
Pros to route caching: Sitespeed gets faster
Cons to route caching: Requires to re-cache every time a change is made so its usually only done so on a production server.
Related
I'm facing a wired issue with Laravel where routes with multiple parameters (both mandatory/optional) aren't working.
Environment Information
Local: Windows, XAMPP, PHP 7.3
Production: Ubuntu 18.04, PHP 7.4
Initially, I suspected issue with .htaccess file but that seems not to be an issue.
This works perfectly on my Local, but for some reason, that doesn't work on Ubuntu Server.
The following code works perfectly.
Route::any('route/me/','Tst#routeme');
However, any of the following doesn't work:
Route::any('route/me/here/','Tst#routeme');
Route::any('route/me/here/{id?}','Tst#routeme');
Route::any('route/me/here/and/here','Tst#routeme');
Any suggestions where I can look up to fix this out, please?
My first suggestion would be to place the route with most params at the top like:
Route::any('route/me/here/and/here','Tst#routeme');
Route::any('route/me/here/{id?}','Tst#routeme');
Route::any('route/me/here/','Tst#routeme');
It's more like which ever route matches first gets executed first so from top to bottom the least param route matches last.
Second thing i would suggest you to group the routes like:
Route::prefix('route/me')->group(function () {
Route::get('here/and/here', 'Tst#routeme');
Route::get('here/{id?}', 'Tst#routeme');
Route::get('here', 'Tst#routeme');
});
for better readability...
I can't give you specifics on why this particular scenario is happening but, matching your development and production environments should elimate these problems in future.
Homestead Docs
The Homestead vagrant box provided by the Laravel team is a solid choice and well documented. It is an Ubuntu 18.04 / 20.04 machine and can be configured with many add-ons. You can easily configure which version of PHP any given project is using with a single line in the Homestead.yaml file.
Docker Docs
Docker is a little more advanced but very flexible in how it can be configured. It's container design allows you to isolate the dependencies of one project from the next.
These aren't that difficult to setup (easily done within a day or two) and allow you to replicate your production environments almost perfectly.
It will help massively in those "but it works on my machine" moments!
updating my own question so that might be of some help for others.
I would say probably this is the last thing that someone (or at least me) failed to check. I tried to list the routes in my server and found my newly added route was not found.
php artisan route:list
Earlier, I cleared cache, restarted apache but didn't help. Finally found the following commands to be a lifesaver when routes are cache & aren't working.
So the thing that worked for me - clearing the "route" cache.
php artisan route:cache
php artisan route:clear
My hearty thanks to #Spholt,#Akbar khan, #Spholt, #Gzai Kun for helping out.
I am building a simple website in Laravel 6. I used the built in Laravel artisan tools to create authentication routes and views.
After logging in, a user should be redirected to /home. However, every now and then Laravel will redirect to /js/popper.js.map
I have no idea why Laravel is doing this! I have scoured error logs, to no avail. I am using Bootstrap, but I never explicitly told Laravel to import or use Popper. I have no idea why it specifically wants to go this specific file?? I've had this problem for weeks.
Sometimes running php artisan config:cache and cache:clear help, but not always. Furthermore, it sometimes will happen on my remote server, or on local, but often not at the same time, making it very hard to debug.
I have declared the Auth routes with the built in Laravel Auth. Like so:
php artisan ui bootstrap
And in web.php:
Auth::routes();
I expect logging in to redirect to /home, which then redirects to welcome/red (part of my software). Instead, it gets stuck at js/popper.js.mapand 404s. Logging in WORKS, and I can access authenticated content. But it's a bad user experience to get stuck in a 404 page for no reason.
Does anyone have any clue where Laravel is getting the idea to redirect to /js/popper.js.map? Thank you!!!!
I’ve never had this issue. Maybe you could start with a simple controller and view? Without any assets and packages loaded? From that point add packages and assets one by one. You should find your bug. And did you write any tests? That should help a lot!
And I assume this popper.js file is loaded by a npm package? Maybe it helps to uninstall it?
I have a strange error in my Laravel(5.6)/app. Whenever there is any route request in the app, all css, js, bootstrap and icons files reload all over again in the browser. I'm debugging this app from last 2 days. And I have no clue what's going on.
I worked on this project a few days ago and it was working fine then I started working on some other project and after a couple of days when I worked again on this project to add some new features, it is behaving like this. Whenever I request any route in the app, all the assets download and load again in the browser. I didn't provide any code sample here because I don't know where the error might be.
If there have been an error in some particular file then that particular route would have behave that way. But all routes reload all the assets all over again. So I just want your opinion is this ever happens to you and how should I tackle it?
If you wanna recreate this project then here is the GitHub link. Git Repo . Recreating this project is very easy. Just create a database. run migrations and then seed the database. For sass and js ,run 'npm run dev' if needed.
Update: Solution to this problem is, don't use buit-in server of laravel, it sucks. Use any php development stack like xampp, wamp etc. and it will work fine.
So I have been working on Laravel projects with no issues at my new job, however I decided it was time to get it up and running on my system at home which for purposes of this question is running MS Windows 10. I managed to get it all set up correctly, however upon trying to get the test app working just to make sure everything was correctly configured, I am unable to get passed the laravel welcome (welcome.blade.php) despite having the Routes.php file in place.
The clean project was git cloned directly from laravel/laravel and I had no issues with this working on my work computer when I very first started learning Laravel. I'm not getting any errors, the routes are simply not working!
Btw I had to create the Routes.php file manually for some reason, even though I created my migrations and did:
artisan migrate
The views directory I created called 'testview' is being completely ignored in the routes file when calling:
Route::get('/', 'TestController#index');
Controller code:
Return view('testview.index');
That is within the public function index() just for those who try to be smart and say "oh but you didn't have it contained within a method".
Please could someone help and tell me where I'm going wrong??
It seems that for some reason the version of laravel on GIT is out of date as I peformed a different command line action using Composer and that installed the latest version. So in closing I've sorted this out myself, thanks.
I want to deploy a Laravel 5 project to shared hosting from my localhost but I am facing so many problems. I have uploaded all files in a subfolder of my shared hosting (PHP 5.5) and when I try http://domain.com/subfolder/public its showing me 500 error. I check the laravel.log but found nothing, set the storage/ to 777 but still no changed (showing last error from localhost).
I also check .htaccess and it seems good. I search a lot and try so many thing but still facing same problem.
Now, my shared hosting give access of SSH so I have installed a new Laravel project. Then copy my edited and added file except vendor from my localhost to Hosting. Then I update the composer and dump-autoload, Now my application is working file.
But I am not sure about the process I did. Is it the right way (I don't think so)? Please let me know what was the problem of directly uploaded file and is there any problem if I use second system for my production app.
There are chances that your route cache is messed up. It is safe to artisan route:clear, artisan cache:clear, and artisan view:clear before uploading your files to ensure that no compiled script left - which usually tied to specific path.
But it is unclear, could you share your stacktrace for your error (and if possible share where your .htaccess file and it's content)?
sorry i can't comment, need higher point. However, by looking at your statement that it works by moving your files (controller, views, public, etc) but not the entire project, i believe clearing caches is the best to try.
As for the deployment of laravel project, there are methods suggested in laravel.io. It is not a good idea to expose your entire laravel files in public folder. Nevertheless, there are many ways to deploy it.
I know it's a little late but you need to either:
1. Make laravel's public folder the root folder of your domain or
2. Make a sub-domain and point the root folder to your projects public folder. The disadvantage with this is that your sessions cannot be connected directly to your main domain's sessions.