•  7 min read  •  389 views

Piece of Cake: Laravel or CakePHP for your Project?

Piece of Cake: Laravel or CakePHP for your Project?

During a recent project, I worked on a CakePHP codebase which was the latest iteration of a legacy codebase that was migrated and refactored to CakePHP. While fundamentally similar to Laravel (and any other modern MVC framework) there lots of differences and lots of things I missed after having done Laravel development over the past few years. In this article, I try to do a high-level comparison of CakePHP and Laravel.

Laravel: An unstoppable Force

Laravel has been around for 10 years and has steadily grown both in adoption and capabilities. Sometime around 3 or 4 years ago it become obvious to anybody willig to take an objective look, that Laravel had reached what can be see as critical mass and that barring any disastrous decisions by it's founder and development team, it would continue to be the dominant PHP based framework.

There are a number of reasons why Laravel can be considered to have reached critical mass:

  • Extensions/Packages: just about any functionality that you can think of is available as an addon to Laravel. This makes is very easy to leverage complex functionality in your apps and thus saves you a lot of time and effort.
  • Development speed: Currently Laravel gets anywhere between 10 and 20 pull requests per day. This is an substantial rate of potential change ('potential' because not every PR is accepted and merged) which basically guarantees that Laravel's capabilities will continue to grow at a faster rate than other PHP frameworks. Since the Laravel stewards have shown a good hand in guiding it's evolution, we can assume that tthe current trend will continue for the foreseeable future.
  • Commercial support: Laravel has established a sizable commercial ecosystem with premium development partners and lots of companies having tangible experience that you can rely upon if you have a budget for hired, professional help.
  • Community: The Laravel community is very large and just about any question you ask in your favorite search engine will result in a few useful results.

CakePHP: Crisp but slightly stale

CakePHP was released in 2005 and for a while, was a very popular framework. These days, even though it's still being actively maintained and developed, it is one of a few frameworks which are still a viable option if for some reason you don't want to use Laravel.

CakePHP supports most of the features you would expect from a modern Framework:

  • MVC architecture
  • Routing
  • ORM Layer
  • Template system
  • Migrations & Seeders
  • Modular architecture leveraging lots of 3rd party components (mostly Symfony)

These are the main points, more could be listed here but this summarizes the global architecture CakePHP and pretty much all modern PHP frameworks use. So you may wonder, if they all have the same basic architecture, what's the difference. Read on and be enlightened as I will attempt to answer your question.

What's wrong with CakePHP?

The clear answer to this question is "nothing". You may at this point raise your eyebrows and wonder "why did you call it slightly stale?"

Let me explain: The fact that nothign is wrong with CakePHP doesn't mean that it's also quite "right", especially when compared to Laravel. Laravel just feels more mature and polished, has more bells and whistles and an incomparably larger and more active ecosystem. In the PHP world, Laravel has become the IBM of frameworks (by this I mean that in ages long past, there was a saying that Noone ever got fired for bying IBM, meaning that it was the safe choice because it was enterprise and everyone used it.

So, here are some of the things CakePHP is missing when compared to Laravel:

  • Advanced routing: route groups, etc.
  • Advanced ORM: rich API, extensive support for relationships, polymorphic relationships, etc.
  • Template engine with inheritance
  • Extensive collection class: Cake has a collection class, but Laravel's is more powerful
  • Mature GraphQL support: Laravel does this through Lighthouse, CakePHP doesn't seem to have an equivalent
  • Extensive community with lots of extensions
  • Solid searchability for help: much of the stackoverflow-type posts you'll find for CakePHP will be for older versions and it's not always clear how applicable these are to CakePHP 4.

As you can see from this list, it's not that case is missing some essential features, but rather that while it provides most of the features Laravel provides, these features generally are more mature in the Laravel framework.

What is CakePHPs main Benefit

I would contend that the main benefit CakePHP provides when compared to Laravel, is that it's easier and faster to become productive in CakePHP. Laravel has become a full-featured framework that in many cases provides ways of doing things the Laravel way. Ultimately these features allow you to write really tight code and make you more productive, especially on a larger & more complex codebase, but you'll need 6-12 months in order to feel at home in Laravel.

In CakePHP the ramp-up time is much quicker and you'll be able to write productive code sooner, albeit at the cost of not reaching the deep integration and productivity Laravel offers. Often in Laravel, if feels that you're coding Laravel code rather than PHP code, that is, much of what you're doing is extremely powerful but very Laravel specific. With CakePHP, you're definitely closer to the PHP you may be used to seeing. Cake is good, it's relatively modern but it's not as tight and fully-feated as Laravel.

An interesting twist on this view is that it is possible to essentially use both CakePHP and Laravel as a routing engine with an ORM and then write more traditional code in this manner. This can be very useful if you have legacy code to migrate; just because these Frameworks offer a bunch of features, they don't force you to use these. You won't be using the full power either system (especially so in the case of of Laravel), but you'll be able to write more traditional PHP code and you won't have to learn everything that CakePHP and Laravel offer (which, to be honest, is quite a bit).

A word about Documentation

CakePHP has a reputation for having fantastic documentation. In practice, I found CakePHPs documentation to be good, but nothig out of the ordinary. Maybe this reputation is a leftover from it founding years when standards were much lower and documentation was a sore point for many (most?) open source systems, especially so in the PHP world. CakePHPs documentation is good. It's sometimes a bit light on the details and could do with more (and more detailed) code examples, but the same thing can be said of the Laravel docs. My main gripe with the documentation for both systems is that they tell you how things are done, but not necessarily why you would want to do certain things. But lets be honest: we are talking about a framework's documentation here, not a course on advanced web development.

What would I advise?

Well, due to market dynamics, adoption rates, development pace and community size/activity, I would advise you to use Laravel, especially if you are planning to write a larger project which will need to be supported long-term.

On the other hand, if you are not familiar with Laravel and have a deadline looming, CakePHP may be the better option since it's definitely easier to become productive using CakePHP. Also, if you have a legacy codebase to migrate, CakePHP may be the easier path forward since you'll be able to keep more of your old-style code without feeling weird (in the sense that you're not using much of what your framework has to offer).

Both CakePHP and Laravel are good frameworks, it's just that Laravel is more mature and more fully featured, giving you more (and often better) options. However, this comes at a cost: if you want to use these frameworks to the fullest of their potential, the Laravel learning curve is steeper than the CakePHP one. At the same time, I think should have a very good reason for not chosing Laravel. Whatever you do, choose wisely, fellow code slinger ...

Related Posts