When I develop a Laravel application I used to clear cache after making any changes to routes\web.php or routes\api.php. Recently I was working on a project for a fellow and found out that the project does not need clearing cache every time I make a change in any of the files I have mentioned.
So I want to know what is the problem with the autoloader or what exactly is the general problem?
When you use commands like
php artisan optimize
php artisan route:cache
your route files(under routes/) are being parsed and cached. Now, next requests will be routed from cached routes, not from routes/*.php.
If you have used above commands, after making changes to route php files, you should re-cache them, or use
php artisan route:clear
to remove the cache. Then, next requests will be routed by routes/*php files.
Related
We already have a Laravel web app hosted in the cloud (AWS EC2 instance). Let's say that changes will be required to be made, such as revising the (blade view) layout or adding new reports.
After I make the changes to the local controller, view and route files, do I simply copy them to the cloud host? Laravel keeps a cache of the blade view files. Will they be updated when the blade view files are updated? What other items do I need to do?
The views caches will be automatically regenerated, but you can force delete the cache if you want. php artisan cache:clear.
For routes, it's parsed from the file, so no worry there.
If you change config at some point, make sure to run php artisan config:clear.
If you touch the services and something is still not working, try php artisan clear-compiled. it will force the regen of the bootstrap.
The best way would be to use a source version control software like git and implement a pipeline on a service like GitLab.
I recently implemented one with this tutorial.
It exploits GitLab pipelines and Larvel's Envoy to automatically run tests and deploy your code that passed each stage you defined. It also allows you to rollback to previous versions at any given time.
For deploying PHP applications in any framework, you can use various tools. The most simple is PHP Deployer, and i recommend you to use it if you're not familiar with automatic deployment. You can set a sequence of commands which will be launched during deployment e.g.
git pull origin master
php artisan cache:clear
php artisan migrate
Whenever I try to update my project in Artisan, the commands I run work, but some of them take a very long time to execute.
For instance, here is a section from my api.php:
Route::apiResource('questions', 'QuestionController');
php artisan serve works in my terminal, and this route is accessible.
But when I delete this questions route, I expect the route host/questions to become inaccessible. However for about a minute after running the command, I can still access the route through the normal URL as if it wasn't deleted.
So what exactly is going on here? Is this caused by caching, and if so, how can I prevent this?
I want a leave-reload thing for my Laravel project.
I'm recompiling my files using ctrl+c, php artisan serve every time, and using Laravel 5.8 with PHP 7.3.7.
This is probably because Opcache keeps a copy of the files for a moment.
Try to disable opcahe and try again.
Check php.ini and see if opcache.enable is on "1", if so, change it to 0, and restart php artisan serve
I'm using Laravel 5.4 on Windows 7 and Xampp 3.2.2. A few days ago Laravel started ignoring the changes I was making to the .env file. I couldn't find the solution so I reinstalled Laravel in a different directory and imported my app folder.
Now Laravel just stopped responding to the changes I am making to some PHP files. I added a function to the /vendor/illuminate/support/helpers.php but I could not access it in the view. I deleted the content of the whole file and I could still access the function previously declared in it.
I created a helpers file as instructed here but that too is being ignored.
Any changes to any views is immediately effected and php artisan cache:clear is not doing anything.
How is this happening? Does it even make sense?
Laravel caches config values to improve performance.
You need to run either (recommended)
php artisan config:cache
which will cache the new values you have, or
php artisan config:clear
which will turn off caching. I've had some experience with this causing errors though.
I know it might sound rather stupid, but have you remembered to restart the server because you've edited the .env file?
I have a Laravel 5.3 project which was created 5 months ago, today I made a duplicate from the project and I made some changes into the code.
When I edit the views in a blade.php file my project which I edited showed me the last project view, I made a new route in the new laravel project and in the routes works well, but still shows the last project view.
It's funny because the js files works pretty well, but the view doens't work. for example, I edit the profile.blade.php file and it shows the content from the last project, if I writte something new in the other view from the last project, it shows in the new project.
Any ideas?
Thanks in advance.
Your views/routes are compiled/cached.
The storage directory contains your compiled Blade templates, file
based sessions, file caches, and other files generated by the
framework.
The bootstrap directory contains files that bootstrap the framework
and configure autoloading. This directory also houses a cache
directory which contains framework generated files for performance
optimization such as the route and services cache files.
Run these commands
php artisan view:clear - Clear all compiled view
php artisan optimize --force - Optimize the framework for better performance
php artisan config:cache - Create a cache file for faster configuration loading
php artisan route:cache - Create a route cache file for faster route registration
Disable opcache from php.ini or use:
ini_set('opcache.enable', 0);
I am updating view and refreshing the route which is rendering that particular view. But it loads previous view. After multiple refresh I get the latest updated view. Can you please explain me in detail how my view should not be cached and i should get updated view only.
In Laravel 4.2 you can't run the command php artisan cache:clear to remove the views. That's because they aren't cached, their compiled.
Laravel 5.1 and greater implemented the command php artisan view:clear to clear compiled views, but here is a custom command you can use in Laravel 4.2 to clear them:
https://gist.github.com/cjonstrup/8228165
Otherwise, just delete all the files in app/storage/views and views will be re-compiled.
I'd recommend to set debug to true, open your browser dev tools and check the option to don't cache pages when dev tools are opened and finally, give 777 permissions to you storage folder (I don't remember the name of the folder in Laravel 4.2) where compiled views are stored as sometimes the system can't write on that location.
I think it should be enough for you to get the view updated on refresh.