3, 2, 1… Go! Yii vs Laravel
More than 80% of all the websites including the big fish like Facebook, Wiki, WordPress, and Pinterest were built with PHP which makes it the major server-side scripting language in the universe of web development.
There are eight more or less popular PHP frameworks today, however, Yii and Laravel tend to make it difficult to make a choice.
When you look at Google Trends graphic, you see that at some point Yii was much more popular, but then something happened, and the situation changed drastically.
If you ask any backend developer at JustCoded what they prefer more, you will hardly find a person who will say both frameworks are good to work with. There always has to be the winner and the scapegoat.
Is it the hype? The marketing? And how are you supposed to determine the right technology for your project?
We will look deeply into Laravel first.
What you should know about Laravel
First, let us say a few words about why a PHP framework should be used in web development instead of native PHP:
- no need to fetch the data from the database by writing complex queries;
- the MVC pattern takes the development process to another level;
- the platforms follow the rule of DRY, which makes the code shorter and more impactful;
- security comes first. PHP frameworks cope with this issue better than raw PHP.
- a lot of must-have built-in features which you need in a typical website: routing, mailing, translations, authentication, request, and response pre-process, error handlers, logs.
Laravel: a short overview
The first release of Laravel happened 11 years ago.
Written in PHP 7, this open-source framework is by far the most widely used among the others.
Initially, the framework was designed as an alternative to CodeIgniter for creating web apps using the MVC (model-view-controller) pattern.
The platform is intended for building complex and meticulous code bases.
Laravel has inherited its power from various solutions; both built on PHP and other frameworks: Ruby on Rails, ASP.NET.
Key features of Laravel
- The embedded components for cache, session, authentication, and queue are the strongest advantage of Laravel, which makes the platform stand out.
- Laravel is characterised by great modularity thanks to IoC (the inversion of control), which enhances class dependencies management.
- Excellent migration systems for databases make it possible to use the framework both in small and large teams.
- An enormous community of supporters and comprehensive tutorials (read Laracasts) considerably facilitate the learning curve.
- The solution is good when it comes to creating Restful Web Services.
The dev team behind the Laravel framework claims that their product is the best solution for fast development.
A few facts about Yii
The official release of the framework was in 2008, the current version of Yii is 2.0.15.
Despite the fast-paced development, Yii is still lagging behind Laravel according to the usage statistics.
The official website claims that Yii is a fast, secure and efficient PHP framework designed for creating bespoke web applications.
Just like Laravel, Yii has an open-source code and was initially intended to eliminate the disadvantages of PRADO framework.
Advantages of using Yii
- It’s ideal for rapid development as it has code generators for CRUD operations.
- Just like Laravel, Yii utilises the DRY coding rule, which is very helpful for writing a well-structured and sophisticated codebase.
- Yii has many built-in widgets to validate or output data quickly with Ajax support.
- The platform is extensible; one can alter any tiny piece of code and build custom extensions.
- Yii was designed to improve the website performance and loading time is faster comparing to Laravel.
- The clear and intuitive mechanism of Yii makes it easy for users to create themes and skins and to extend Yii core.
- There are millions of supporters willing to share their knowledge of Yii through educational resources.
In short, Yii is a perfect fit for web applications demanding high-performance and logical coding.
Laravel or Yii for web development: who is the winner?
Now let us have a closer look at the frameworks and discover similarities and differences between Yii and Laravel.
Both frameworks can be set up with a Composer, a PHP package manager. After downloading you have a built-in web server and a working website sample.
Laravel also has a simple helper to speed up the installation with a standalone command-line tool.
When setting up a Yii project, you will get an advanced template deployed in your environment. It has a separate backend and frontend that you can use for developing the admin area and a user-facing site, for example.
Laravel installed a much simpler “example” project – a simple blog.
However, it has a better structure comparing to Yii. With that said, we created a modern Yii2 project starter, which is very close to a new Yii 3 coming up next year.
Laravel: the validator stays as a separate class allowing developers to do the validation whenever and wherever they want.
Also, it’s possible to extend the Eloquent class using custom methods. As for the scenario-based validation, its mechanism has not been thoroughly thought through. There is no way one can define attributes with fillable property based on multiple scenarios. For this purpose, you will need to customize the code.
Yii: the platform has a unique client-side validation coupled to the class of a form or a model.
One can set rules and check the compliance of form validations with these rules once the data is received and filled in ActiveRecord. In case you have another form altering the data in a model, you will need either to develop a specific class for it or apply custom validation scripts. It’s very convenient until you don’t need your own verification methods.
Both solutions come with a multitude of awesome extensions for lots of scenarios.
Any drawback of a framework can be turned into an advantage with the help of a couple of extensions. They’re super easy and handy both for freshmen and experts.
Laravel: some may find it surprising but Laravel lacks ready-made tools for access control. However, this problem can be solved with a snap of a finger – by using one of the extensions.
Yii: to be honest, Yii offers much more when it comes to security issues. It has a configurable built-in Role-Based Access Control. It doesn’t mean that Laravel is worse, you can enable similar security features from configuration or use an external extension.
Both Laravel and Yii have excellent migration tools enabling dev teams to organise the working process in a smooth and convenient way.
Also, both of them allow database seeding. In Yii, you can generate a fixture and use it to seed the database.
Both frameworks have millions of supporters all around the globe and their number is increasing every day.
Laravel is rather geared to skilled developers while Yii is easier to start with and is accessible for everyone.
Besides, Laravel has great publicity and promotion. The famous Laracon will happen in July 2019 at the Play Station theatre in New York.
Newbies can always rely on the helping hand of experienced Yii specialists.
Laravel: the docs are well-prepared and detailed, although for middle-skilled specialists the language may seem to be a bit complex.
Yii: the documentation was not well-documented, but it has been updated recently and offers a lot of useful information. It’s written in a generic way so that even those with basic programming skills can master the development process.
To make the results of the overview more illustrative, we’ve created a comparison table.
Let’s dive into the tech specifications of Laravel and Yii.
Yii vs Laravel for web development
|PHP requirements||PHP 7.1.3 +||PHP 5.4 +|
|Extensions||Yes||Yes (less than in Laravel)|
|CRUD generation||No default support||Gii module for fast code generating|
|ORM (Object-relational mapping)||Eloquent ORM provides ActiveRecord implementation.||Default ORM. Also has support for various databases|
|Routing||Resource routing (a route is supposed to be mentioned for action in a controller)||Default routing (no need to declare a route for each and every action)|
|Caching||API for various caching systems||Diverse caching|
|Testing||PHP unit testing and Symfony testing||Codeception unit testing|
|Debugging||Debugging console and Laravel-debug bar extension||A debug toolbar. Debugging console as a 3rd party extension.|
|Widgets||No default support||Built-in widgets for HTML and Ajax data tables, custom widgets, Bootstrap, and JQueryUI widgets|
|Template system||Blade||PHP templates, Twig is partially supported|
|Form validation||Validation as a separate class||Built-in to Model classes|
|Code scaffolding||Laravel Artisan, extensions||Gii code generator, console, extensions|
|RESTful APIs||Good for RESTful apps||Built-in CRUD operations for RESTful APIs|
|Security||ACL plugin and Access Control Filters||RBAC and built-in tools for input validation, output filtering, etc.|
What to choose – Yii or Laravel?
These questions are to help you with choosing YOUR framework.
- What do I know about the tool-kit of the framework?
- Is it easy or difficult to build a web app with the framework?
- Is the framework extensive?
- Does the framework continue evolving?
- Do the developers support the framework?
- How large is the community of the framework?
We can say that Laravel is perfect for large-sized and complex web applications as it is equipped with numerous features.
Yii is a convenient and comprehensive tool for smaller projects, and each framework has its own pros and cons which are important to take into account:
- Validation. Yii has a unique client-side validation coupled to the class of a form or a model.
- Project setup. Laravel example has a modern project structure instead of Yii.
- Extensions. Both solutions come with a multitude of awesome extensions for any occasion.
- Security. Laravel lacks ready-made tools for access control.
- Migrations. In Yii, you can generate a fixture and use it to seed the database.
- Guidelines. Laravel for middle-skilled specialists the language may seem to be a bit complex.
The biggest benefit of Laravel is its laconic core system with highly organized components, which allows Laravel enthusiasts to write elegant code.
Laravel has inherited the best PHP practices and this fact attracts more and more programmers all around the globe.
The learning curve for mastering Laravel is very steep and not every newbie can overcome it. However, they have all the resources needed for learning and even a Laravel course called Laracast!
Yii’s “one-click installation, out-of-the-box tools for CRUD and authentication, built-in widgets and solutions work perfectly for swift coding.
Although it’s older than Laravel, version 2 is still fresh and educational resources for learning it requires fine-tuning.
The takeaway is that there is no winner in this battle, sorry for the false expectations.
Before you rush to either Laravel or Yii, think hard about what exactly you need from the framework. After all, your goal is to have a working website no matter what tools have been used for its development.
Drop us a line if you are doubting about the technology for your project – we’ll try to consult you and suggest a suitable solution.
Maybe it’s not PHP at all? 🙂