Symfony and Laravel, the same language: what are the key differences?

  • #Frameworks & development
  • #Technical & Entreprise Architecture

Publié le Mis à jour le

Symfony and Laravel are amongst the most popular frameworks on the market. While Symfony dominates in French-speaking countries, Laravel is often cited at the top of the list in English-speaking rankings. This cultural difference can of course be explained by the French origin of SensioLabs’ product.

Laravel is still very inspired by Symfony, using 11 of its components. We are familiar with the American habit of appropriating foreign new features, both in technology and the cinema.

Despite the many points in common between these two frameworks, one based on the other, what are the main differences?

Container accessibility

  • The Laravel Service Container allows managing class dependencies and dependency injections without any configuration. A simple type-hint is enough and everything is managed automatically in the background.
  • In Symfony, it is possible to obtain a similar result with Autowire and Autoconfigure.

Twig vs Blade

For templating, Symfony uses Twig and Laravel uses Blade, although it is easy to use Twig with Laravel thanks to TwigBridge.

  • The syntax of Blade is just a simpler and more explicit version of PHP which means that everything that can be done in PHP can also be done with Blade. This offers great flexibility but has the disadvantage of allowing many more bad practices.
  • Twig is more constraining to ensure good coding practices. As it works in a separate context, all function calls and filters are limited by the explicitly declared functions.

For example, in terms of security, since Blade is no different from PHP, it is easier to cleanly escape variables, however the engine does not impose any restrictions Finally, Blade makes database queries possible.

Apart from that, the two template engines are similar.
For example, template inheritance and section import are identical except for the syntax:

Doctrine vs Eloquent

Eloquent uses the Active Record pattern where the model layer is both the representation of the database and the place where operations are performed.On the other hand, Doctrine goes through an Entity Manager where the entities are representations of the database tables.
Consequently, Eloquent requires fewer lines of code to operate and is easier to understand.

However, in practice, the two systems are very similar, especially with Entity Manager’s recent updates that make it look like Eloquent’s Query Builder.

There was a time when only Doctrine had a migration system but now Eloquent has one too, very similar except for the syntax.

FormBuilder vs FormRequest

Where Symfony has FormBuilder to facilitate form generation, Laravel has no equivalent system. The forms must be manually declared in Blade. However, it has FormRequest which allows managing everything concerning the validation of the form separately and upstream of the controller.

Profiler

Unlike Symfony, Laravel does not offer any Profiler out of the box. However, there are various packages such as Telescope and Laravel DebugBar that can be used instead.

Learning curve

Symfony is a big and relatively strict framework that seems to have planned everything with its crowd of default components, which is a definite advantage but makes it harder to apprehend for people who are not familiar with frameworks. To put it in another way, the learning curve is steep.

Laravel is more permissive, with all the flaws that this inherently involves. It is also simpler with a basic MVC architecture. This makes it more accessible and easy to learn for the beginner.

Lumen vs Silex

Laravel and Symfony both have their micro-framework equivalent, Lumen and Silex respectively.

Lumen seems more specialized than Silex. It focuses on the development of micro-services and APIs with an emphasis on speed of execution. Silex is more generalist. It is no longer maintained since June 2018, because since then, Symfony is more granular.

Cache

Laravel has no equivalent to HTTP Cache from Symfony. For example, in Symfony, you just have to declare Redis or Memcached in the services to be able to use them. On the other hand, Laravel offers a uUnified API to use Redis, Memcached or DynamoDB.

Community

If we compare Google Trends searches, we can see that Laravel is very far ahead of Symfony internationally. In France it is the opposite, Symfony is largely dominant. For other French-speaking countries like Belgium, Switzerland or Quebec, the gap is smaller but Laravel keeps its predominant position. A developer with a good level of English will find a larger community than for Symfony, but Symfony has the advantage of being very convenient for French speaking people with a smaller but very active community.

Conclusion

Despite the few differentes listed in this article, the two frameworks have a lot in common.
With equal technical skills, for most projects, either one or the other framework can be used indifferently without too many consequences.