in 2011, Laravel framework community has grown and now it is the best PHP
framework in 2017. From simple web app to complex API's, Laravel is a perfect
PHP framework which can fulfill creation of all complex features. With its
simple elegant syntax building applications, it feels like having fun. It
provides a set of libraries which makes it easy to build web app using well
structured and beautiful code. Database migrations, powerful Active-Record implementation
(Eloquent), powerful unit testing, routing, highly tested HTTP layer and many
more features Laravel framework as a power packed PHP framework.
These tips are based on 5+ years of experience in providing Laravel Development Services. Hope it will help the naive PHP developers.
Here are some tips for you so you can develop better applications.
1. Enhance Artisan Command Uses: Laravel framework has a unique tool named Artisan command which is helpful to boost performance. If you are using a lot of routes and configuration, then you should create a cache as plain array so your application loads faster.
- php artisan config:cache
- php artisan route:cache
- php artisan optimize --force
When you change config or route file, don’t forget to re-run these commands or Laravel will not handle changes that you’ve made. By running these commands, we also limit locations, settings and user data. So when you change data, make sure you invalidate the cache.
2. Remove Unused Service: If you are not using service, don't load that service in your config file. But after commenting that service code make sure that your app works properly.
3. Minimize the Use of Plugins: Plugins reduce our development time by adding more functionality to our project. But when we add a plugin, we add some files and libraries to that project. Use a plugin when it is required. Cutting down your composer.json file will cut the dependencies that are loading.
4. Profiling Your Queries: Ever wondered what happens
when you execute a query? To know install a Laravel package profiler from https://github.com/barryvdh/laravel-
Once you add this, it will add a console where you can view all SQL queries issued for that page.
5. Use soft deletes: Delete operation shouldn’t be a straight delete operation that deletes permanently because once a user deletes that the record, he cannot get it back. If you want to give this permission to your user, use SOFT delete. Enable soft delete in your models by protected $softDelete = true; property. Moreover, you are required to add a column deleted_at using datetime property.
6. Optimize Memory: If you have million records, then these operations are very heavy for RAM. Use Eloquent's chunk method to handle this thing.
foreach ($res as $rs)
// operations here...
Here 1st parameter defines size and 2nd parameter is the closure that defines what to do with that chunk.
7. Protect App from bots and spammers:
web site pretends to be some other web site this concept is known as Cross-Site
Request Forgery (CSRF). By this someone can hijack users’ access to your web.
In Laravel Framework you can protect all inbound routes.
Thanks for Reading!