Laravel | CakePHP comparison
- Laravel is a PHP open source frammework. Laravel is developed and maintanced by Taylor Otwell. Its architectural patterns are majorly based on Symfony.
- Although Laravel was created quite late (2011) compared to other PHP frameworks such as Symfony (2010), CakePHP (2005). But to now, Laravel is framewok leading in the number of users, stars on Github and also searches on Google or StackOverflow.
Star on Github
- And according to Packagist’s statistics, Laravel has nearly 13 million installations.
- The latest version of Laravel is version 6.4 (released on October 24, 2019).
- In addition, Laravel has many other advantages to choose as a framework for web development.
Advantages of Laravel
- Laravel syntax is easy to understand, learn and use.
- Laravel has a rich and easy to understand documents.
- Built in MVC model.
- More built in function: Laravel provides many features available to make the development of web applications faster. As with just one line artisan command:
php artisan make:auth. You have some features: registration, login, logout, password forgotten with no additional lines of code.
- Configuration management: With Laravel, you can easily manage configuration and run projects in some different environments with just one command line to switch between environments.
php artisan env - -env = testing
- Artisan: Laravel’s command-line management tool. This tool we can easily create Tables, Models, … Laravel’s management tools display more detailed information than CakePHP. Example: shows route information in a project.
Laravel displays more complete information: names, methods, URIs, middleware and actions.
CakePHP only displays information
- Manage routing in Laravel is divided into separate files like api, web. Therefore easier to manage, especially with large projects. In CakePHP, the default is stored in a routes.php file.
Laravel has PHPUnit testing built-in. After install a new Laravel Web application, we just need to run
phpunit. When running tests with PHPUnit, Laravel will automatically set the environment configuration to testing. In addition, Laravel will automatically configure the session and cache into arrays during testing. This means that no session or cache data already exists during the test. Alternatively we can create a .env.testing file in the project. This file will overwrite .env file when running PHPUnit or run Artisan command with –env = testing option.
In the tests folder there are divided into 2 sub-folders, Feature and Unit, respectively for test functional or unit testing. To create a new test case, we use the command
– Create a test in the Feature folder
php artisan make: test UserTest
– Create a test in the Unit folder
php artisan make: test UserTest --unit
With CakePHP, we will have manually install it with the following command
php composer.phar require --dev phpunit/phpunit:"^5.7|^6.0"
And to run the test use the command
- Blade template: Symfony has Twig template, Laravel has Blade engine template. With Blade template, users do not need to use PHP code anymore. Such code will be beautiful.
CakePHP view template
In addition, Laravel also support developer to check authentication. We needn’t send an relate information (user roles, login status …) to the view as in CakePHP.
- File system (upload file): Can easily work with File for you to store that file locally, Amazon S3, FPT or Rackspace Cloud Storage with just a few simple configuration steps. Laravel uses the Flysystem library and supports the use of local filesystems, Amazon S3, FPT, Rackspace Cloud Storage.
When using Amazon S3 service and Rackspace Cloud Storage, you only need to install the relate package with Composer then add and edit the setting information in enviroment file (.env) and in directory config/filesystem.php without any additional code. Saving a lot of time compared to CakePHP.
- Eloquent ORM: retrieving data through the Model with nice code syntax, but it seems to be slower than Query Builder when retrieving complex data.
- Frontend: Compared to CakePHP, Laravel has integrated support for using Vuejs in the project. By default Laravel uses NPM to install packages for the frontend.
- Laravel has some library: cashier (billing service), envoy, passport (authentication for API service), scout (full text search), socialite (authentication with Facebook, Twitter, LinkedIn, Google, GitHub and Bitbucket).
- API: Laravel returns a response faster than CakePHP. For example, when testing an API to get a product list. In all 5 tests, Laravel still has a shorter run time.
Cakephp Laravel 1 245 153 2 318 189 3 533 172 4 396 179 5 390 192 Average 376,4 177
- Validations: The code validation in Laravel is beauty, easy to read, the rule and custom messages is two separate function. The validation in Cakephp is written in the corresponding Model file of each table. But in Laravel, the validation code will write in a separate file.
- Migrations: the migrate in Laravel is more shorter and run is faster than CakePHP.
Migration run time: