Laravel

What’s new in Laravel 5.5

Max Hutschenreiter -

And another Laravel version is on it’s way to us (developers, code enthusiasts), and of course, as in any other version there will be things that some of us will like, some of us won’t. These are the things that I think, you should pay attention to.

New LTS
As you all may now, Laravel 5.5 is predicted to be the next LTS (Long Term Support) release. We had 5.1 as LTS (Jun 9, 2015), but now it’s time for refreshment. In December last year, Taylor Otwell said it probably won’t be LTS,

nah i don’t think so. LTS is sort of an anti-pattern IMO.

— Taylor Otwell (@taylorotwell) December 16, 2016

but as time goes by seems that he and Laravel elders change their minds. So yup, this should be new LTS.

No more old PHP
Laravel 5.5 will definitely be a big deal to all developers that are still on any version of PHP below 7.0. As it is announced, it will require PHP 7.0+, so be aware of this before you switch to it.

Whoops is back!
Yes, yes, you read it correctly. The error-handling framework which was used in Laravel 4 and removed from Laravel 5, now it’s back. I personally like whoops, as it makes all the PHP errors and exceptions a little less annoying with changing how they appear. Also, good thing is that it doesn’t have any dependencies.

Custom error reporting
Although there is a way to change this in Laravel 5.4, you need to dig into the Handler class exception method to you can do something there. In 5.5 you’ll need only to register report() method in your custom class and Laravel will check if there is a report method in your class and execute it if there is.

throw_if() and throw_unless()
Yes, Laravel 5.5 brings us two new intuitive functions for exception helpers which do exactly what they say. It’s best to show them on examples:
//throw_if 
$check_this = true; throw_if($check_this, new MyException(‘This is true’)); 
//or 
throw_if($check_this, MyException::class, ‘This is true’);

//throw_unless
$check_this = false; 
throw_unless($check_this, new MyException(‘This is not true’));
//or
throw_unless($check_this, MyException::class, ‘This is not true’);
as you may see, it is pretty obvious how they work.

A new way of customizing validation
As we all know, custom validation rules are not a new thing in Laravel, but new we will be able to have a dedicated class for it. All you need to know about this is that you’ll have to implement Rule and you’ll need to have method passes() and method message(). So to use it you’ll need to pass a string with rules like this:
$request->validate([ 
    'someField' => [ 
        'required', 'min:4', new CustomRule() 
    ]
]);

Model (factory) generators
One more convenient new feature from Laravel 5.5 is model generators which enable you to generate factory, controller, or migration while generating a model.
php artisan make:model Client -f //factory
php artisan make:model Client -c //controller
php artisan make:model Client -m //migration 
and you can also generate factory
php artisan make:factory ClientFactory

migrate:refresh
Another witchcraft from Laravel will speed up things and make our lives a bit easier. migrate:refresh will drop all of the tables and start from scratch while php artisan migrate:rollback will go through each method and run the drop. So this way it’s much faster.

Blade::if() Directives
For me, one of the nicest things about Laravel is the blade template engine. I really like my code clean, and Blade is all about cleanliness. New Blade directives are here to make our blade templates even cleaner than they are in Laravel 5.4. Check out this:
Blade::if('env', function ($env) {
    return app()->environment($env);
}); 
and in template
@env('production')
    <a href="http://some-prod.js">http://some-prod.js</a>
@endenv 
smooth as silk.

vendor:publish gets a provider prompt
As we all know, in previous versions vendor:publish all published all that there is: configs, migrations, views…
But now, if you run the command without any flags you’ll get prompt about what to publish. If you want to bypass it you can add either —all or —provider flag.

Frontend Presets
This is pretty straight forward, so you can now remove all Vue and Bootstrap scaffolding in one command:
php artisan preset none 
or you can add one by one as you want:
php artisan preset bootstrap 
Also, you can add React this way:
php artisan preset react 
For the future of presets, we can just guess for now, since Taylor didn’t mention any further plans for now.

Conclusion
These have been my top picks from new things in Laravel 5.5. Yes, it’s a big thing to exclude all PHP versions before 7.0, but for new starters, this won’t make any big difference. As a matter of fact, it will force them to forget ancient versions of PHP. LTS? The great thing, since the last LTS was published two years ago, so it’s time for a new one. What are your thoughts about this?
Tags: Laravel · New

Want products news and updates?

Sign up for our newsletter to stay up to date.

We care about the protection of your data. Read our Privacy Policy.

Impressions from our Team

  • Another day another #mandarinacakeshop 🎂 😀 - #

  • Happy Birthday Ognjen! And marry Christmas to all other 🎄#notacakeshop - #

  • #Office #Garden - #

  • #workhard - #

  • #belgrade #skyline - #

  • #happybirthday Phil :) - #

  • #happybirthday Stefan 🥂 - #

  • #happybirthday Lidija 🍾 - #

  • Say hi 👋 to our newest team member ☕️ - #

  • #bithday #cake 😻 - #

  • #stayathome #homeoffice #42coders - #

  • #stayathome #homeoffice #42coders #starwars :) - #

  • #stayathome #homeoffice #42coders - #

  • We had a really nice time with #laracononline #laravel - #

  • Happy Birthday 🎂 Miloš - #

  • Happy Birthday 🎂Nikola - #

  • #42coders #christmas #dinner what a nice evening :) - #

  • Happy Birthday 🎂 Ognjen - #

  • Wish you all a merry Christmas 🎄🎁 - #

  • #happybirthday Luka! - #

© 2021 42coders All rights reserved.