Access all articles in sprocket icon.
Published September 23, 2016 by Bill Keck.
Top 10 Reasons Laravel Is Such A Great PHP Framework
I found writing this article a challenge because I love Laravel and it’s hard to distill that love for the framework down to a top ten list, so in that sense, I’ve failed before I have even started. On the other hand, programmers are always looking for a sense of direction. For those unfamiliar with Laravel, they may ask, ‘Why favor that framework over others?’
So I boiled it down to this list, just to provide some insight from insight from someone who not only uses the framework personally, and has written a book about it for beginners, but also as someone who has seen the benefits of using the framework at the enterprise level, since my company uses it for that.
So here we go:
1. Commitment to Excellence
Laravel, or more precisely Taylor Otwell, has a mission, which you can find in the readme.md file of any Laravel installation. Here are 3 sentences from that statement that say a lot:
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching.
Now it’s one thing to talk about expressive and elegant syntax, another thing to actually accomplish it. Laravel actually fulfills that promise and it’s done so with Taylor Otwell’s long term vision.
At this point Laravel is 5 years old. It works so well and is so intuitive, it’s easy to forget that’s the product of an evolution and the pursuit of consistent ideals.
In 2013, Taylor Otwell wrote a 67 page book that talked about his approach to Laravel. I read that book for the first time, as a beginner, in 2013, and I had no idea of what he was talking about. I reread that book a year ago and it was so cool because I could see how the framework had evolved in exactly the ways he laid out in the book.
Without doing a full review of the book, I’ll just hit a few points. He talked about escaping the limitations of the MVC architecture, the value of loose-coupling though dependency injection, and the limitations of the notion of a model in MVC.
I do recommend that book by the way, but not if you are a beginner, it will not help you with the basics. It does however offer a fascinating glimpse into Taylor Otwell’s sense of architecture. Plus, buying a book is a nice way to say thanks for all the work he has done with Laravel.
Anyway, the point of bringing up the book and talking about the evolution of Laravel is you can see what he was committed to early on and how he actually executed on it. The Laravel we know today didn’t happen by accident. It’s the result of a long-term commitment to excellence, best practices, use of SOLID design principles, and the steady vision of the founder, Taylor Otwell.
2. Constant Evolution & Growth
I started following Laravel in 2013, but did not actually use the framework itself until Laravel 5.0 came out, which was in 2015. That was the moment, to my mind, when it blew away the competition. It seems like such a long time ago, but as of this writing, it’s not even 24 months. And in that time we went through 3 more releases, which gets us to 5.3, as of this writing.
5.1 introduced long-term support, which made it ideal for enterprise work. I wrote a blog recommending it because of that. There were other changes to, but I can’t keep track of them all at this point.
In 5.2, we saw the make:auth command which created all the authentication views with a single artisan command. So you could use the out-of-the-box authentication to get up and running in under a minute and have all the functionality, including forgot password. It’s so easy. And in 5.2, they introduced login throttling to prevent attacks via login, another nice improvement.
5.3 saw a lot of changes including separating the routes file into web and api files. Stateless auth is now one of the options that you can stand up quickly by changing the config, so if you feel your project is going to scale to the point where sessions will degrade performance, you now have another option.
Prior to 5.3, I wasn’t using Elixir, but with the Vue.js implementation, I finally started using it, and I have to say, it’s amazing. I have Elixir as separate item in my top ten list as well. It’s that good.
It isn’t just new features that get added to Laravel. For example, in 5.3, there is a new mailable class you can create with Artisan. There was nothing wrong with the old way of creating a mail event, but that didn’t stop them from improving it. The syntax and structure is so elegant, it’s just a pleasure to work with, which putting it that way, makes it sound like it comes right out of the mission statement in italics from the first item on this top ten list. Again, that’s not an accident.
The only downside to rapid growth and evolution is that you have to work a little harder to keep up. I have found that it is worth upgrading to the latest version in every case because I want to use one or more of the new features. To help this go smoothly, Laravel has an upgrade guide for each version available in the docs.
Laravel has beautifully written and comprehensive documentation. I recommend to anyone who wishes to learn the framework to read the docs from start to finish, it’s worth your time to do it.
Sometimes great programmers struggle to communicate with the written word, but that is not the case here. Instead, we get precision and clarity and it’s very helpful. You will use the docs often.
I find myself referring back to the convenient lists of the validators and migration syntax often. It’s just so easy to use. Have a question about how to use Redirect? Just type that into the search field in the top nav, you will find what you need.
Also, and this is part of the ecosystem, the Laravel forum has many answers to common problems. One of the benefits of using a widely adopted platform is that you get the benefit of all those other programmers who have tried doing the same things as you have, and you can find their examples and solutions.
If I ask myself the question, what would I change about the Laravel Docs, the answer is simple. Nothing.
As I mentioned above, I didn’t start using Elixir until recently because I didn’t have much of a front-end focus. But with the introduction in 5.3 of Vue.js being installed and configured out-of-the-box (after running npm install), I was motivated enough to try it. Now I wouldn’t dream of creating a project with out it.
Elixir is super-clean and super-easy to work with as of 5.3. Personally, I think it’s a huge contribution to the framework. We will discuss Jeffery Way’s other huge contribution on item 10 of our top ten list, when we talk about Laracasts.
5. Out-Of-The-Box Authentication
In the 5.2 release of Laravel, we got the make:auth artisan command, which, with a single command, will create all of your auth views, including login, register, and forgot password. That’s a lot of code generation from a single command, and it is a pleasure to use.
Before you run the command, you already have the controllers and traits in place, since those ship with the framework. You also have a User model and the corresponding migrations for both the users and create_passwords tables.
The bottom line is that you can this all working within a matter of minutes, and you are getting a robust solution that includes login throttling.
I’ve enjoyed working with the Auth Controllers and traits, which are now, as of 5.3, separated into a LoginController and ForgotPasswordController. I do an implementation of Socialite for Facebook and Github, which I will talk about more later, based on the out-of-box solution.
So far, with every version release of Laravel, I’ve had to update it, since the controllers and traits are being changed, but I don’t mind. These are critical areas of the framework and I want to stay current and have access to new features and the very best that the framework has to offer.
6. Artisan & Code Generation
If you want a demonstration of self-affirming syntax, then the following explains it well:
php artisan make:
That is something you would type in your command line to do an Artisan command. Artisan is Laravel’s command line tool and it’s deep. Just to give you an idea of some of the code generation commands, here is a list of make commands:
- make:auth Scaffold basic login and registration views and routes
- make:command Create a new Artisan command
- make:controller Create a new controller class
- make:event Create a new event class
- make:job Create a new job class
- make:listener Create a new event listener class
- make:mail Create a new email class
- make:middleware Create a new middleware class
- make:migration Create a new migration file
- make:model Create a new Eloquent model class
- make:notification Create a new notification class
- make:policy Create a new policy class
- make:provider Create a new service provider class
- make:request Create a new form request class
- make:seeder Create a new seeder class
- make:test Create a new test class
If we add -m flag to make:model, we get the corresponding migration. If we add –resource to make:controller, we get 7 restful method stubs on the controller.
Obviously there is more to Artisan than I can cover in a simple list like this, but I do have to say that it is wonderful to work with. And you can tell by the different types of classes that it can generate just how helpful it is. For example, the make:test command will generate a stub, not only extending the right class for you, but also in the tests folder. So it puts the generated classes in the proper places and namespaces the for you as well. Again, it’s a pleasure to work with, and again, that’s not an accident.
7. Plays Well With Others
In a very basic sense, Laravel is a service container that holds service providers. Those service providers power the application. Many of the service providers are deferred, which means they are only called when needed. They include the core framework providers as well as providers for outside packages.
To add a service, for example, if you want to add a package, you may run the composer require command, and then add the service provider via config/app.php and also the alias if there is one. That’s a total of 2 lines and just doesn’t get any simpler.
This makes Laravel very extensible and there are thousands of packages on packagist.org that you can extend your application with. I can’t claim to have worked with some enormous number of outside packages for Laravel, but what I do know is that I never had a problem installing the ones I have used, other than the occasional typo on my part.
Laravel also comes with sensible defaults. For example, out-of-box, you care configured for mailtrap.io in your .env file. So all you have to do is use the one-click registration with your github account on mailtrap.io, grab the credentials, paste them into your .env file, and you are ready to test your forgot password emails. Total implementation time is under a minute.
Laravel is built using Symfony components. And you may ask, why not just use Symfony? I know personally for me, I found Symfony a lot harder to work with and to learn. I don’t know the current state of Symfony because I haven’t felt the need to play with it in a long time. But that’s not why I brought it up. Laravel’s core is built with Symfony, Doctrine, the Faker library, Carbon and other libraries. All of these components work flawlessly with Laravel, and to me, that says a lot about the application structure and implementation.
I don’t know that I would use a framework because it returns my created_at and updated_at fields as carbon instances, but is an example of another great detail that makes the framework a pleasure to use (see again mission statement in item 1).
With Laravel, you can set the filesystem to a non-local drive. For example, if you wish to store your images on Amazon S3, you can easily configure Laravel to do so for you. That is a very practical feature of the framework.
Creating, Updating and Retrieving data from the database can be a real chore. The problem stems from the fact that data is stored in smallest structures possible, for example, a user’s name in one table and their address in another. We can join these together using raw SQL, but Laravel’s syntax makes this a lot easier. With Laravel, we create methods that define the relationship, then we have access to a number of methods to get the value of a property of a relationship. It’s so simple.
I’m not going to get into the exact syntax here, but I’ll link to the eloquent docs. The fact that Taylor Otwell would name his ORM Eloquent says a lot about what he is trying to accomplish.
Laravel also has a fluent query builder, which you can use in situations where you don’t want to use Elqouent.
Often what I find is that use many of Laravel’s different ways to access data. I use DB::raw to create a select statement that formats the date a certain way. Normally, I would use Carbon for formatting, but that is not always possible when building queries dynamically.
If I just want to iterate over a collection of posts, I use Eloquent:
$posts = Post::all();
Then you can do a foreach loop in blade to iterate over each one. I don’t know how much simpler it could be than that. Again, I’m not going to go too deep into syntax, since wordpress doesn’t cooperate with publishing code.
With big datasets, you need to pull the data out in chunks for pagination. Otherwise, if you had a large database, and you ran a query for all, you would put a strain on the DB and return more rows than are practical to display.
Fortunately, Eloquents pagination is super easy to use:
$posts = Post::paginate(10);
So in this case, we retrieve data, paginated in groups of 10 records. I’m showing you this not for instruction because this is not a tutorial, but to show you how intuitive this syntax is.
9. Official Packages & Extensive Ecosystem
The Laravel framework has a number of extremely useful packages that we can add via composer that extend the framework. One that I’ve used often is the Socialite package.
Socialite provides 0Auth authentication via Facebook and other sites like Github. It works very well and is fairly easy to implement. Depending on how you want to implement social authentication, the implementation can be a little more complex, if for example, you want one-click registration as well as one-click login. But Socialite eliminates the most complex parts of that and it’s just great.
I haven’t used Cashier personally, but I know some programmers who have, and they love it. Cashier provides an implementation for Stripe, which is an online payment gateway.
Laravel Passport help us quickly implement an API for stateless auth. I haven’t used this personally, but I’m excited about using it at some point in the future.
Laravel also has a number of commerical services that support it, including:
I’ve used Forge personally, and what that does is automatically configure a server, let’s say a droplet from Digital Ocean, to deploy your application. It’s pretty easy to use and the cost is low at $15. I’m not really a dev ops guy, so I found this service to be a big help.
My company uses Envoyer to deploy its applications. Envoyer helps you deploy an application instantly, without any down time. It works incredibly well.
I don’t know that much about Spark because I haven’t used it, but it’s a paid template that acts as a starting point for an application.
So those are the commercial services, with the exception of one, which I’m going to talk about in the next top ten list item.
Laravel also has the following community resources:
One of my favorites is Laravel News. I look forward to the new issue, which comes out for me on Sunday mornings. Obviously, I have used the forum on more than one occasion to find an answer to a problem.
The podcast is a lot of fun, and you typically get a behind the scenes look at what’s coming down the road.
The bottom line is that there is a lot support and learning resources available.
10. Jeffery Way & Laracasts
I never met a single programmer that didn’t like Laracasts, no matter their skill level. I started watching Laracasts in 2013, which is when it began, if memory serves me correctly. As a beginner, back then, I struggled. Even though there are free videos for the basics on Laracasts, I didn’t quite get it. In those days, there were lots of instruction about the importance of dependency injection, but it all went over my head.
As I developed as programmer, gained experience from other frameworks, I started to understand more and I grew to really love those videos. I try not to miss an episode, regardless of the subject. He covers everything from lessons in Git to regular expressions to setting up and using Redis, and of course everything you want to know about PHP and Laravel.
As an outsider looking in, it seems to me that Taylor Otwell and Jeffery Way share an enthusiasm for a keyword driven approach to syntax. I really connected to that more than anything else. I’ve always been fascinated by syntax, in terms of both good and bad, and how it facilitates comprehension or how it degrades it.
Both the framework and Jeffery Way’s implementations of it maximize the best aspects of syntax. Another way to say that is they make it easier to understand. I think they have probably both studied Robert Martin’s Clean Code book, which was published in 2009, but remains an iconic work.
I’ve had conversations with programmers about whether or not Laravel is suitable for beginners. A lot of them say no, but obviously I wrote a book for beginners, so I feel strongly that beginners should get started with Laravel as soon as possible. I would also say, sign up for Laracasts as soon as possible. I’m not, by the way, paid by anyone to say that. I never met Taylor Otwell or Jeffery Way, so it’s not personal. It’s just that I appreciate their influence and the impact they have had on my professional life.
One of the great things about Laracasts is that it gives you a window on to what trends are happening. For example, I first heard about Vue.js at Laracasts.
At our company, we debated for a few months whether or not we would use Vue, but that ended about 3 months ago, and now we wouldn’t dream of not using it. Everyone loves it. Laracasts has an entire series on it. Anyway, we wouldn’t have even known about Vue if not for Laracasts, which is one reason why we bought a company license.
Laracasts is a huge plus for Laravel, so much so that I would call it a competitive advantage. Having a resource like that available is another reason to love the framework.
Ok, so that’s my top ten list. I hope you enjoyed it. Like I said, it falls short of course. Maybe my next blog will be the Top 100 Laravel Features I love or something like that because there are at least that many things that I love about it.
Thanks to everyone who has followed my blogs and read my books. Please like, share and comment if you can. I appreciate your support.