Laravel vs Symfony — Major Differences

Содержание

Michał Ciążyński

For each project, it needs to be decided which technology to use. For web development purposes, firms most frequently decide to go for PHP frameworks. But which of them to choose? Today, I decided to introduce the two most popular PHP frameworks: Symfony and Laravel, and thus compare their similarities and demonstrate differences along with their usefulness in terms of specific types of projects.

Framework overview

Symfony

Laravel

8.4.1 (10 November 2020)

MVC-based. Modular structure, multiple-use code.

MVC-based. Some of the dependencies available from the start allow getting started quickly.

Twig – uses filters to modify data.

Blade – ability to insert any PHP code into the skin body.

Doctrine ORM. Out of the box supported databases

  • Drizzle,
  • MySQL,
  • Oracle,
  • PostgreSQL,
  • SAP Sybase SQL Anywhere,
  • SQLite,
  • SQLServer.

Eloquent ORM. Out of the box supported databases:

Designed for large projects with a long-term perspective in terms of their development.

Simplicity and the speed of the code to be written.

Basic information

Symfony is a PHP open source license framework which uses the model-view-controller project design pattern. It is most frequently selected for large, complex projects. Symfony 2 was released in 2011 and this year should be considered the beginning of the framework, nowadays known under this name. Symfony 1 was an entirely different project, with different underlying assumptions.

Release date: 2011

Recent stabile version: 5.1.3 (1 May 2020)

Laravel is a PHP open source license framework which uses the model-view-controller project design pattern. Initially released in 2011, however, along with version 4, released in 2013, the interest in the project had increased significantly. Laravel is currently the most popular framework on the market. Its authors point that the intuitiveness, simplicity and speed of the code written are the greatest strengths of this framework.

Release date: 9 June 2011

Recent stabile version: 8.4.1 (10 November 2020)

pasted image

Similarities

Basic information regarding these frameworks already reveals many similarities between them. What strikes first is the fact that both frameworks are the open source license available solutions and use the PHP language. Moreover, the ability to deploy the system with additional modules and components as well as multiplatform design, are the factors that make Symfony and Laravel similar.

Database related work support is in both cases similar to both systems use ORM (Object–relational mapping) — Doctrine in case of Symfony and Eloquent in case of Laravel.

At first glance, both frameworks may seem to be almost like twin solutions, but as usual, the devil is in the details.

Symfony — distinguishing features

Contrary to Laravel, Symfony was developed especially for large-scale projects which affected most of the decisions made when designing it. If we provide Symfony development, at Droptica we typically work with large projects or projects where Symfony is an underlying technology. This is because Symfony is used by many known projects, including Drupal, PrestaShop, Magento or as a base for other frameworks: just to mention Laravel, Yii or CakePHP. It demonstrates its versatility and flexibility.

Symfony is developed as a modular solution which is composed of mutually independent elements (bundle). These are installable file bundles already containing certain functionalities. A good example of such a bundle may be an instant messenger or a payment system. This type of solution allows us to make the code independent of the system being written and use the bundles created for other projects.

The advantage of Symfony, which is frequently emphasised is its performance. And although I can openly advocate for this statement, it is good to have in mind that the speed itself depends on the components and basic elements we use. Because it is hard to expect a powerful performance when the bundles used are badly designed and simply operate poorly. The simplest thing to say is that the Symfony’s performance is the sum of its individual performances – the base performance is an extremely efficient base.

The community around Symfony is still one of the largest networks, thus solving issues or expanding applications with add-ins developed by users, is a really pleasant job.

As its template engine, Symfony uses Twig. This solution generates template files with .twig extension down to the PHP code. This is a widely known and generally used solution that we use within our offer of PHP development services. The performance and simplicity of the written code is certainly its advantage. The disadvantage, however, is the fact that twig gives no possibility to inject the PHP code — so we have to use filters instead.

We are, however, not limited to use solely the filters developed by Twig authors – we may create such filters by our own and expand their number. Exemplary Twig file:

Laravel — distinguishing features

The first and the most important thing to know about Laravel is that this framework is developed on Symfony components. Laravel also uses Symfony as its frame; however, supplements it with its logic and vision to write software using PHP language. The basic principle for Laravel is intuitiveness and the quickness of writing code. The authors presume that considering today’s market demand for programming solutions, the time and resources should play a key role in the project being created. Although such thinking may seem right, many people point to the short-sightedness of such an approach, and thus Laravel is often associated with smaller “at-short-notice-type” projects. In order not to scare you away from the start, I would like to say that even if there is an element of truth in this, all this, in fact, depends on the people who use the solution and how they take advantage of its potential. Our Laravel developers are happy to use the speed to their advantage, but also take time to architect modular and robust, future-proof soloutions.

The logics, as already mentioned, strikes just after installing Laravel. The framework welcomes us from the start with ready dependencies and fully ready-to-work environment. Contrary to Symfony, for those who do not wish to configure everything from the start by themselves, Laravel provides some tools necessary to work. Already mentioned Eloquent ORM or vue.js can be one of the examples that we get out of the box. For beginners or those who value their time, it may be more seamless and quicker to enter the world of programming, comparing to Symfony. Such a solution also has some drawbacks, as most probably, we will not use all the options that Laravel offers us from the start and which means plenty of unnecessary code maintained in the project.

Magic methods may also be an element that „buys” many people while choosing the right framework for their needs. In short: they ensure the speed of code writing with no need to create complicated and complex code lines. They help us to focus more on the logic of a given project’s performance rather than the code itself and its correctness.

Another very useful feature of Laravel and the functionality we get right from the start is the authorisation system which is so crucial for web development. Contrary to Symfony, this framework is already equipped with a system supporting authorisation, and the configuration on our part is limited to database configuration at migration.

Contrary to Symfony, Laravel uses the Blade engine as the template engine. However, this is a disputable issue as, in my opinion, this is a better solution than Twig. At a basic level, both solutions are quite similar in terms of operation; however, what distinguishes Blade is the ability to insert the code directly in the template file. This small difference makes working with templates considerably more superior.

Exemplary Blade file:

Summary

The choice of a suitable framework is never easy. I hope that my text may, at least slightly, help you understand the major differences between the two most popular solutions for PHP. And I call it „major” differences deliberately as the number of smaller differences would be enough to write at least a series of books. Both frameworks have been designed with a different end in mind and for different reasons. I leave the task to choose the right framework to you, although, whatever you decide, I am sure that you will be satisfied.


Источник: www.droptica.com