Open with fade-zoom animation

Stay ahead...
Receive latest updates directly in your Inbox!

Whats New in Laravel 5.5

What’s New in Laravel 5.5

Laravel 5.5 is scheduled to release in August and probably during LaravelEU. Laravel 5.5 is the most awaited version as it is an LTS (Long term support) release after Laravel 5.1. For LTS release bug fixes are provided for 2 years and security fixes for 3 years.

Laravel 5.5 will need a minimum of php7.0+, so if you haven’t yet upgraded to PHP 7 its right time to do it.

Here I have created a detailed list of new features coming in Laravel 5.5. The list keeps on increasing as we read about important new features.

Whoops Error handler:

It was present in the previous version of Laravel but was removed. With Laravel 5.5 it is coming back. It provides a pretty error interface that helps developers like you and me debug errors easily.

Package link: https://github.com/filp/whoops

Streamlined Request Validation:

CSRF error:

When submitting a form if there is no CSRF token or CSRF token is expired it will show a meaningful error: “The page has been expired due to inactivity. Please refresh and try again”

Better approach for Validate:

Previously when you need to validate a request in controllers you need to write it like:

But with Laravel 5.5 provides a better object centric approach:

Validate returns the validated data:

The validate method above will also return the validated data. So, no need to add the extra statement to get input data after it is validated.

Note: Validate will return value for the data only which is passed for validation. If you haven’t passed some field then you will have to use request object to get it.

Migration:

Migrate Fresh:

Delete all tables and migrate them again. There is a similar confusing command Migrate re-fresh. The different is re-fresh will first roll back all migrations and then migrate them. But Fresh will simply deletes/drops all table (no rollback here) and migrate all migrations.

This is really helpful indeed.

Frontend Presets:

Present provides quick scaffolding for different javascript framework. In laravel 5.4 it had a default scaffolding using bootstrap and vue. But in laravel 5.5 you can use artisan command and generate scaffolding.

You can either choose none or vue or bootstrap or react and it will create a quick scaffolding to get started.

Automatic Package Discovery:

Everytime you install a package, you will have to go to app/config.php and add the provider, aliases etc. It needs to be done for every package we install. But in laravel 5.5 it will be automatically discovered by reading the composer.json files. No more changing the config.php file after installing a new package.

Faster Email Layout Testing

Previously when you need to implement Mailable class(E-mail), we need to send out the email multiple times just to check if the layout looks good. But with Laravel 5.5 you can render email directly in a browser. You will need to return the object of the mail class created and it will get rendered.

So if our class is Welcome, we can render it in a browser by return new App\Mail\Welcome; Technically the Mailable class implements

Technically the Mailable class implements the Renderable interface.

Custom Validation Rules:

New artisan command to create custom validation is added. To add a new custom validation run:

It will create a Rules directory and the class inside it.

You will have to implement the validation logic and the error message. For this 2 method passes and message needs to be implemented.

To use it for validation:

Collection Dumping:

Previously when you want to dump a collection you needed to dd or var_dump, like below example:

Now if want to check the blogs collection after each chained method, we need to comment them and dd it.

and so on for other methods as well.

But with Laravel 5.5 there is a new method dump(), with this you can simply add it to the chain after each method and it will show separate output for each of them.

Model Factor Generator:

In previous versions of Laravel there we a single ModelFactory File, where all factories need to be added. This may get huge with time.

With Laravel 5.5 you can define different factories for different Model.

This will create a BlogFactory file where we can define the factory for that Model.

Factories help to create/generate dummy test data set, which can be used for testing purposes.

Custom blade “if” Directives

This is a cool feature added in Laravel 5.5.

If we need to have the same “if” logic in multiple views/places, we can define a custom directive for it quickly and easily.

To define a custom blade directive, go to AppServiceProvder.php and define the directive in boot method:

To use it in view:

 

Auto-register Artisan Command

If you create a new artisan command you will no longer have to switch to kernel.php and register it there. The command will auto register.

******

That’s all we have for now.

Did we missed something important? Any other suggestion? We would love to hear back from you.

No Comments

Leave a comment

Your email address will not be published. Required fields are marked *