PHP frameworks provide solutions to common web application requirements such as security, input validation, and database connection to name a few. There are a plethora of frameworks to choose from and it is often down to the developer to pick one. Some developers tend to stay within familiar grounds after working with a framework whilst others are more adventurous and make a long term commitment only after they've had the chance of testing a few popular frameworks. Making a choice is often affected by a project's requirements as well as the framework's popularity, performance, features, learning curve, and documentation availability.
Laravel is a free, open source, PSR-2 compliant PHP framework which follows the MVC architectural pattern, among other architectural patterns it elegantly makes use of (e.g. Factory, Facade, Event Driven, Observer, Singleton, Dependency Injection, RESTful and Active Record). In the past couple of years, it has gained a lot of popularity and is now the chosen framework for many web application developers, backed up by an ever increasing community. Its eloquent syntax and approach to common tasks is what makes developing more enjoyable and keeps many developers in favourable terms with PHP.
CodeIgniter is Laravel's main competitor and it has slowly decreased in popularity, proportionally with the latter's increase. CodeIgniter recommends using their own styling guide and it only recently introduced standard request methods such as PUT or DELETE, which it has been missing in previous versions. CodeIgniter relies heavily on the singleton pattern and its approach to common tasks is not considered as elegant. For example, database migrations require the developer to keep track of the database version by manually updating a config file as well as specifying the type of migration being used (i.e. timestamp or sequential). Laravel, on the other hand, only requires a console command to create the timestamped migration file and then another artisan command to run the recently created migration, without worrying about versioning. Migrations are being tracked as batches via a database table which makes it easy to sequentially rollback migrations.
Looking at how these two frameworks achieve the same thing (e.g. create a blog table via migrations) can help unveil the benefits of working with a modern framework that enables developers to write cleaner, better looking code.
timestamps()function will add two timestamp columns (e.g.
updated_at) that are managed by Eloquent upon creating or making changes to a database row.
Whilst many developers will agree that Laravel has a steeper learning curve given its sometimes incomplete documentation, the long term benefits are far greater as it offers a solid structure for agile development coupled with a long window of support and maintenance. Thus, LTS versions such as Laravel 5.1 are provided with bug fixes for 2 years and security updates for 3 years.
Laravel also encourages developers to have a peek behind the scenes by using its API to browse the source code and discover new features.
There are many reasons we enjoy working with Laravel, but here are our favourites which CodeIgniter happens to lack:
- Easily configurable user authentication and authorisation. Registering users, logging in, resetting passwords, and checking permissions is a breeze with Laravel
- Creating, reading, updating, and deleting resources is made easy with Eloquent data models and resource controllers
- Managing multiple database resources or custom data sets is very elegant using Laravel's Collections
- Blade templates simplify displaying information and maintaining an application's layout using a powerful engine
- Filesystem provides an abstraction layer, useful when working with local, FTP, or cloud storage
- Built in testing support for automated tests including session mocking
- Creating classes that define an application (e.g. controllers, models, migrations, requests, etc) is painless when interacting via its artisan console commands
Another area where Laravel shines is its exceptions that are accompanied by an incredibly helpful and detailed stack trace which eases debugging. Extending features with the use of Composer packages is another feature that CodeIgniter only introduced recently but not by default, whilst Laravel is fully manageable via such packages. Probably our favourite is the debug bar as it aids the development stage with database query monitoring (including queries performed via AJAX requests), exceptions, session variables, routes, events, and views as well as application profiling. CodeIgniter has its built in output profiler but due to its inability to profile AJAX requests, a third party package would be preferred.
Looking at a Google trends graph from the past 12 months, we can see how Laravel distances from its main competitors
Laravel's creator, Taylor Otwell, did not try to re-invent the wheel thus, a peak behind Laravel's bonnet will reveal that it's using many core components from Symfony (e.g. Console Commands, Routing, Event Dispatcher, HttpKernel, and Translation). Symfony is best regarded as a framework build using a set of reusable PHP components. These robust components are being used in a variety of other PHP projects such as Magento, Drupal, Composer, PHPUnit, Doctrine, and Codeception to list a few.
CodeIgniter's ownership has been recently transferred from EllisLab to British Columbia Institute of Technology and there are talks about version 4 which will make use of namespaces, Composer, PSR standards, and better RESTful support however, these are just rumours for now. Meanwhile, Laravel is hosting international conventions focusing on in-depth technical talks, development workflow, tips for organizing code, and in general how to more easily solve complex problems.
Tastes differ and choosing a framework is always debatable however, when it is about new features, clean code, and the latest PHP version - Laravel is the preferred option. CodeIgniter will always trigger a sense of nostalgia for many developers. Its well written documentation definitely makes it easy to get started with PHP and the MVC pattern. Laravel is a suitable option for web developers looking to keep up with the industry and find simple elegant ways of solving complex problems.
Simplicity is the ultimate sophistication (Leonardo da Vinci).