Why I Love Laravel And You Should Too

Laravel has exploded in popularity. It has become one of the most popular, and widely used PHP frameworks in a short span of time. It's been close to 2 years since I have started using it; and I must confess, Laravel is indeed an elegant framework. This post will cover my experience using the Laravel framework, why I love it and why it is highly recommended for all the PHP developers.

What is a framework?

As developers, we all get to a point in our careers, where we start to find redundancy in building similar functionalities, and defining similar structures across different projects. This is the point where we would probably go on to build ourselves a framework; which would have the said desired structure, and all those functionalities included. Or we would go on to use a more general framework, which provides those functionalities out of the box.

That brings us to the question: What is a framework? According to Wikipedia:

A software framework is a universal, reusable software environment that provides particular functionality as part of a larger software platform to facilitate development of software applications, products and solutions.

https://en.wikipedia.org/wiki/Software_framework

Putting this in the context of PHP and web development, a PHP framework is collection of classes and/or components for building web applications using the PHP programming language, in a much easier and faster way.

PHP frameworks that I have worked with

CodeIgniter is the very first PHP framework I have used. The major reason for using CodeIgniter in the first place, was its simplicity compared to other frameworks like Zend. CodeIgniter was easy to grasp, as I went on to build a few projects with it. While working with CodeIgniter, I realised that a few functionalities like Authentication, Authorization, ORM, Templating Engines, and more, were not included in the framework by default (though there are community contributed addons/plugins). It was then, when I decided to look for a framework that has these features included out of the box, so I can focus on building applications as fast as possible.

During my search for a new framework, I discovered YII, which also follows the MVC architectural pattern, same as CodeIgniter. I tried YII for about a week. Though YII had most of those features which were missing in CodeIgniter, I had to move on with my search, because I didn't like some of the conventions in YII, like prefixing controllers' method names with action.

I had started using the Laravel framework back in 2015, after it was recommended by a fellow developer.

Why I decided to stick with Laravel

Laravel is an open source, modern PHP framework for building web applications rapidly. It also follows the Model-View-Controller (MVC) architectural pattern. Laravel ships with lots of great features which make building web applications simpler, expressive, easier, and faster. Some of these features which Laravel provides out of the box, include:

  • Authentication: With a single command, Laravel will setup a complete authentication system with login, registration, and password reset for your application.

      php artisan make:auth
    

    Running the command above will scaffold an authentication system like below:

    Authentication Image

  • Authorization: Laravel also provides an authorization system which allows developers to easily specify what a particular user can/can't have access to.

      if (Gate::allows('update-post', $post)) {
              // The current user can update the post...
      }
    
      if (Gate::denies('update-post', $post)) {
              // The current user can't update the post...
      }
    
  • Testability: Laravel ships with convenient methods which make writing testable applications much easier.

      php artisan make:test UserTest
    

    This command will place a new UserTest class with a basic test example within your tests directory.

      <?php
    
      use Illuminate\Foundation\Testing\WithoutMiddleware;
      use Illuminate\Foundation\Testing\DatabaseMigrations;
      use Illuminate\Foundation\Testing\DatabaseTransactions;
    
      class UserTest extends TestCase
      {
              /**
               * A basic test example.
               *
               * @return void
               */
              public function testExample()
              {
                      $this->assertTrue(true);
              }
      }
    
  • Routing: Laravel comes with a powerful, yet simple, routing system which gives developers a lot of flexibility when defining routes for their application.

      // you can use closure in your route
      Route::get('/', function () {
          return view('home');
      });
    
      // you can also point your route directly to a controller method
      Route::post('post', 'PostsCOntroller@store');
    
      // named route
      Route::post('post', 'PostsCOntroller@store')->name('save-post');
    
      // you can even create resourceful routes
      Route::resource('comments', 'commentsCOntroller');
    
  • Configuration Management: You can configure almost every part of Laravel through a .env file, containing settings unique for that particular environment. Adding the snippet below to your .env file will tell Laravel to use these settings instead of the ones specified in database.php.

      DB_CONNECTION=mysql
      DB_HOST=127.0.0.1
      DB_PORT=3306
      DB_DATABASE=homestead
      DB_USERNAME=homestead
      DB_PASSWORD=secret
    
  • Database Query Builder: Laravel ships with a fluent query builder, which lets you issue database queries using PHP syntax, where you simply chain methods instead of writing SQL. You can see Query builder in action below:

      // Show a list of all of the application's users.
      $users = DB::table('users')->get();
    
      // retrieve a single user
      $user = DB::table('users')->where('name', 'John')->first();
    
  • ORM: Laravel provides an amazing ORM called Eloquent, which helps developers to work and interact with a database. You can see Eloquent in action below:

      // store a new post in database
      $post = Post::create([
          'title' => 'Sample Title',
          'body' => 'Some body content'
          'author_id' => 1
      ]);
    
      // get all posts of a particular author
      $posts = Post::where('author_id', 1)->get();
    
  • Schema Builder And Migrations: Laravel provides schema builder which allows developers to define database schema in PHP code, and keep track of any changes with the help of database migrations. You can create a migration with:

      php artisan make:migration create_users_table --create=users
    

    And write your table schema using Laravel schema builder:

      Schema::create('users', function (Blueprint $table) {
          $table->increments('id');
          $table->string('username')->unique();
          $table->string('email')->unique();
          $table->rememberToken();
          $table->timestamps();
      });
    

    Then you can run your migration:

      php artisan migrate
    
  • Template Engine: Laravel ships with a lightweight templating engine called Blade, which compiles down into plain PHP code which is cached, hence adding essentially zero overhead to your application. Below is a view file using Blade:

      <!-- This view extends the app layout view -->
      @extends('layouts.app')
    
      @section('content')
      <!-- The content below will be inserted to the content section of the app layout view -->
      <div class="container">
              <div class="row">
                      <div class="col-md-10 col-md-offset-1">
                              <div class="panel panel-default">
                                      <div class="panel-heading">Welcome</div>
    
                                      <div class="panel-body">
                                              Your Application's Landing Page.
                                      </div>
                              </div>
                      </div>
              </div>
      </div>
      @endsection
    
  • Queue Library: Laravel queues provide a unified API across a variety of different queue backends, such as Beanstalk, Amazon SQS, Redis, or even a relational database.

  • Laravel Scout: Driver based full-text search for Eloquent, complete with pagination and automatic indexing. With laravel Scout, you can do:

      $orders = App\Order::search('Star Trek')->get();
    
  • Laravel Echo: Event broadcasting, evolved. Echo brings the power of WebSockets to your application without the complexity.

  • Laravel Passport: API authentication without the headache. Passport is an OAuth2 server which you could get ready in minutes

Of course, these are but a few of the amazing features, and functionalities which Laravel provides out of the box.

Now to the fun part: why I actually love Laravel. Having built a few applications (demos, personal projects, open source projects, and clients' projects) with Laravel in the past years, I have come to love this amazing framework so much. In addition to the features mentioned above, below are a few more reasons that made me love Laravel:

  • Develop faster: Because Laravel provides a lot of great features out of the box, it makes it faster to develop, and get an MVP quickly running.
  • Documentation: Taylor has put a lot of time and hard work to make the documentation as simple, and as straightforward as possible. The documentation is made in such a way that without additional resources you should be able to develop your first Laravel application.
  • Convention over configuration: Laravel follows the convention over configuration paradigm, which simply means you follow some basic conventions in your Laravel applications rather than wasting time on configurations. This makes you develop applications that are well structured, following the modern methodologies.
  • Expressive and beautiful code: Something that is at the core of Laravel is its philosophy that code should be named simply, and expressively. Taking a look at a Laravel code, you would immediately see how the variables, and methods are named — with descriptive names, and structured in an expressive manner.
  • Laravel doesn't get in your way: Despite the fact that Laravel comes with great features out of the box, Laravel makes customising the defualts so seamless.
  • Helps you become a better developer: Above all, Laravel makes you a better developer because it forces you to use modern technologies with standard development practices.
  • The Laravel community: One of the things, which I think has given Laravel an edge over other frameworks, is its community. The Laravel community is so strong to the extent that you will find almost everybody talking about Laravel, willing to help you with your problems, recommend resources etc. Do you need to know the latest about Laravel? There is Laravel News. There is also Laracasts which is a great place to learn about Laravel and modern development through screencasts by Jeffrey Way, who I must say is an amazing teacher.

It is more than just the codebase

Yeah! You read that right, it is actually more than just the code. Laravel provides an entire ecosystem of tools for developing and deploying your applications. These tools include:

  • Homestead: Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create a box in minutes!
  • Valet: Valet is a Laravel development environment for Mac minimalists. No Vagrant, no /etc/hosts file. You can even share your sites publicly using local tunnels. Laravel Valet configures your Mac to always run Nginx in the background when your machine starts. Then, using DnsMasq, Valet proxies all requests on the *.dev domain to point to sites installed on your local machine.
  • Laravel Forge: Instant PHP platform on Linode, DigitalOcean, and more. Push to deploy, PHP 7.0, HHVM, queues, and everything you need to lauch and deploy amazing Laravel applications.
  • Envoyer: This is yet another product by Taylor Otwell, it deploys your PHP applications with zero downtime. Just push your code, and let Envoyer deliver your application to one or many servers without interrupting a single customer.
  • Spark: Spark provides the perfect starting point for your next big idea. Forget all the boilerplate and focus on what truly matters: your application.

Conclusion

There you have it. Those are the things that made me love Laravel. These are based on my personal experiences working with the framework. Laravel is an amazing framework which I can't stop talking about, and as we have seen why, it comes highly recommended for all the PHP developers.

Write your comment…

4 comments

Hey... I do use Laravel framework professionally since 2013 up to nowadays, and I really like and recommend this framework. It is the best. Go for it!

But, sincerely, this enthusiastic merchandise of it makes me laugh. Even myself can't take it seriously. Pardon me, I'm just being sincere: it really made me laugh. Sorry.

Let me pick as concrete example this snippet of three things in a row:

Laravel Scout: Driver based full-text search for Eloquent, complete with pagination and automatic indexing. With laravel Scout, you can do:

$orders = App\Order::search('Star Trek')->get();

Laravel Echo: Event broadcasting, evolved. Echo brings the power of WebSockets to your application without the complexity.

Laravel Passport: API authentication without the headache. Passport is an OAuth2 server which you could get ready in minutes

This sounds like pure marketing. Laravel Echo does not remove the complexity of having WebSockets in your app. It facilitates several functionalities with handy helper stuff - that's it. Please don't tell anyone they'll have their Web Sockets and no complexity. Sounds like Symfony framework merchandising saying how simple is to use their framework! Laughing out loud.

Same thing is valid for all others: Queue, oAuth, text-search - these Laravel features certainly are of high value and drastically decreases development difficulty and time.

But these wordings are misleading: "without the headache", "Event broadcasting, evolved" (meaningless), "without the complexity", "you can do App\Order::search('Star Trek')->get();"...

It looks like all will be magical, fairies will appear and delight you while the app development runs on its own, automatically by Laravel.

Why all these lies? Are you trying to sell Laravel for kids? You will have headaches. You will face complexity. You will have to configure full text search. You will have to act as a professional developer.

That being said, I confirm I greatly admire and appreciate Laravel. It boosts productivity. it really has tons of useful features, and it really does not block your way. I agree with the article point. I just think the article lost its tone and beyond a certain point it started to decrease its own value by sounding like a cheap marketing piece.

So: thanks for the effort on putting this article and publishing it. I support it, and I support Laravel. I just wanted to point out this "room for improvement" on it.

Spot On1

Hashnode is building a friendly and inclusive dev community. Come jump on the bandwagon!

  • 💬 A beginner friendly place

  • 🧠 Stay in the loop and grow your knowledge

  • 🍕 >500K developers share programming wisdom here

  • ❤️ Support the growing dev community!

Register ( 500k+ developers strong 👊)

Laravel is always proved best framework for Php. I came to know many things after reading your blog, which i didnt know about before such as Laravel Forge, Spark and much more. You explained whole laravel framework very well. Thank You. Keep Going.

Clap1

Hmm a lot of devs are in love with it :) I personally don't use it, I am not the biggest active record fan and other architectural designs are a trade-off because they want it to be easy to use.

But maybe one day one customer will insist on laravel, till then I prefer phalcon, zend, symfony or my own one. (My own mainly out of principle ofc ;D) ....

Show all replies

http://ssapptricks.com/adam4adam/

I have enjoyed reading many of the articles and posts contained on the website, keep up the good work and hope to read some more interesting content in the future.

i

Reply to this…

Excellent article.. Thanks for sharing..

Laravel is lovable by most of PHP developers due to some of the features like Laravel is powerful ORM. Also Laravel Migrations, It will do dissertation writing it for you with one particular command. Quick & functional core that can be extended Clean and simple routing.

Reply to this…