Laravel

Highlights of Laravel

one of the most powerful PHP frameworks


This article in Spanish.


Why Laravel?

As a programmer, it is common to have to use an unfamiliar or completely new framework. Imagine working with a tool that has thought put into it about things that need to be used frequently (or useful aspects). Even better, imagine a tool that shows you solutions you never thought of, and that it does it in an easy and intuitive way. It is also important that its documentation is not complicated or difficult to assimilate. This is the case we are talking about Laravel. Laravel is a highly intuitive, well documented, easy to use framework that incorporates current tools that make the development process easy.

I will begin by describing some of its advantages from my personal point of view, based on my experience working with this framework directly.


Fundamental aspects:

 

Installation

Laravel requires a quite simple installation, with just a few requirements:

  • PHP >= 5.6.4

  • OpenSSL PHP Extension

  • PDO PHP Extension

  • Mbstring PHP Extension

  • Tokenizer PHP Extension

  • XML PHP Extension

  • Composer

  • Node

The most critical requirement is PHP 5.6 because its installation varies significantly depending on the operating system on which it will work. Particularly, I develop in Ubuntu/Debian and I use CentOS as the production server. In this scenario PHP 5.6 needs to be installed, but the process is straightforward without major complications.

Starting a Laravel project is as simple as writing a single sentence in the console, since all the work is done by the composer:

composer create-project --prefer-dist laravel/laravel my_project


Configuration

Even when Laravel does not require large configurations, the most critical point is the Application Key to ensure values ​​in session and any other information that must be encrypted.

It is very easy to change the timezone for working with dates and "locale" for internationalization.

Configuration files are well separated and documentation on them is very complete. Some items about configuration files that are important to pinpoint are listed below:

  • App, Auth, Database, Cache, Session: As in other frameworks, these aspects are very simple to configure: we can work with sqlite, mysql y postgresql. We can easily have multiple connections and databases that are interchangeable at any time.

  • Mail: An important point for when we need to work with sending mails, is that Laravel incorporates very simple tools like Mailgun, Amazon SES, Mandrill, and Sparkpost, among others.

  • Services: I love that Stripe is included for handling online payments!

  • Filesystems: Cloud storage with s3 is simple and easy to incorporate. We also have ftp and rackspace -Excellent!

  • Broadcasting: Events and notifications; it incorporates pusher, redis and log (local file).

  • Queue: Just wonderful, and we can handle queues: database, Beanstalkd, Amazon SQS, Redis.

The points that are most remarkable are the notification system, queues, and filesystem -which is not always easy to implement. Laravel makes it very easy for you.


Highlighted features

 

artisan

"Artisan is the command-line interface included with Laravel. It provides a number of helpful commands that can assist you while you build your application."

Commands in this framework are very useful. Here are some examples:

  • make:auth: To have user registration, password recovery, login, logout among others.

  • make:migration: To build our tables and modifications.

  • make:seeder: To seed our database with test or initial data.

  • migrate:refresh: Very useful when we build our database, to keep it updated and send recent changes.

  • make:model and make:controller: To build a base for our models and controllers.

  • make:command: To create our own command(s).

With PHP artisan we can list them all and use them to be more productive.


Security

 

Authentication

With PHP artisan make: auth we have everything: login, user registration, password recovery, we can protect the routes, basic authentication, social authentication, and we can extend and customize processes very comfortably.

Authorization

We can protect resources and actions that the user can access to without much difficulty, as it is all very well modularized. The highlight is that in Blade, we can use guidelines that help us build views according to the established policies.

Facades

With them we can share behaviors between controllers to simplify our code, so it looks clean and all logic focuses on what the controller actually does.

Routing

Laravel presents a common routing system, however, it is very convenient that we can have a routing for web and another one for REST. Laravel is responsible for preparing the request and the response, depending on the route requested by the client. The controllers are not affected at all and decoupling is a great advantage. You can develop your web app or a REST API so you can consume services without inconveniences.

Eloquent ORM

It is a big and complex issue in general, but it is important to note that working with relationships is very easy in this context. Understanding that relationships between entities is critical, the Laravel approach is a great option when working with them. The models do not include explicit relationships, queries are quite fast and it is in the the programmer's hand to define these relations when needed. This is very easy to do just by following certain conventions, as we can see in the following example:

$user->posts()

This statement should return the user’s posts (considering that it is related to the posts). Initially it will not work, so we must define the posts() method on the user model:

public function posts()

{

    return $this->hasMany('App\Post');

}

With nothing more, it is working. Eloquent is very broad, and it could be covered in more detail in another article.

Notifications

We often need to notify a user or group of users about events that occur in our app, and implementations are often not the same. With Laravel we have already developed the process, we can choose different notification systems and we can exchange them in a very practical way. We can send mails, SMS, and so on; we can even spool all these and comfortably manage the delivery if the number of messages is very large.

Queues

Tasks that imply a great resource consumption are very common nowadays, and it is inconvenient for end users to have to wait for a long time until a job is completed, therefore, queues come into play. This allows us to schedule and delegate processes to a service that is responsible for processing them. Many frameworks do not include this by default, however, Laravel offers the necessary logic to incorporate queue handling, including some pre-configured services. Additionally, you can use your preferred service, and the framework gives you the environment you need to be able to use it comfortably.

Conclusion

I have tried a large number of frameworks. I have loved some more than others, but definitely Laravel occupies one of the first places in my ranking because it offers many facilities that most of them lack. Laravel is exciting and fun, prompting you to use current and innovative tools. It is prepared to make great applications in a very standardized coding style, which facilitates application maintenance: makes it easy to documented them, easy to extend them, easy to test them. In short, Laravel is highly recommended!