What are the new features in Laravel 5.5
In this post we will give you information about What are the new features in Laravel 5.5. Hear we will give you detail about What are the new features in Laravel 5.5And how to use it also give you demo for it if it is necessary.
What are the new features in Laravel 5.5
The Laravel community is always ready to launch the new features with its upgraded version and I have too much interest about upcoming features in Laravel.
You will have to upgrade your PHP version if you have installed older than 7.0 because Laravel 5.5 will require PHP 7.0+.
LTS Release
After Laravel 5.1, for LTS release, You will get a long term support policy with Laravel 5.5 including 2 years bug fixes and 3 years security fixes.
Whoops features back in Laravel 5.5
whoops is an error handler framework for PHP used with Laravel 4 but it was removed from Laravel 5.0
whoops provide a nice, clean and elegant interface for error that notify you the error line in the file where you exactly get the error.
Now you can directly open referenced files directly in your editor from whoops interface.
You can set your installed editor in handler file to overrides the whoopsHandler()
method.
Return request data from validation
There are two changes in validation rules in Laravel 5.5. Now you can directly call the validate method on the request, before you pass the request instance as a first argument to validate request data, but with the release of Laravel 5.5, there is no need to pass request instance as a second argument.
- public functionstore()
- {
- $data=request()->validate([
- 'name'=>'required',
- 'email'=>'required'
- ]);
- return Member::create($data);
- }
public function store() { $data = request()->validate([ 'name' => 'required', 'email' => 'required' ]); return Member::create($data); }
And second changes is, You can get the request data after validation in a variable and directly save the data after validation.
- public functionstore()
- {
- $data=request()->validate([
- 'name'=>'required',
- 'email'=>'required'
- ]);
- // $data = request()->only('name', 'email');
- return Member::create($data);
- }
public function store() { $data = request()->validate([ 'name' => 'required', 'email' => 'required' ]); // $data = request()->only('name', 'email'); return Member::create($data); }
But make sure if any attributes which is not required should be defined with the empty rules because you may lose the data, if any attributes which is left out from the validation method.
- public functionstore()
- {
- $data=request()->validate([
- 'name'=>'required',
- 'email'=>'required',
- 'notRequiredField'=>'',
- ]);
- return Member::create($data);
- }
public function store() { $data = request()->validate([ 'name' => 'required', 'email' => 'required', 'notRequiredField'=>'', ]); return Member::create($data); }
Custom Validation Rules
Now you can create your own custom validation rules with Laravel 5.5
With the older version, there was facility to add custom validation rules via Closures using Validator::extend
method but with Laravel 5.5, You will get a dedicated class to handle the custom rules and also you can use artisan command to create a class for custom validation :
php artisan make:rule CustomValidName
You will get the class CustomValidName in app/Rules directory with two methods :passes and message
passes
method will have two method $attribute
and $value
and validate if attribute value is valid then return true otherwise return false and message
method return the respected error message when validation fails.
Click here to see the full example Custom Validation Rules
Blade::if Directives
With Laravel 5.5, You can define custom if blade directives for the different different scenarios.
Click here to see the full example Blade::if Directives
Route Helpers
Now you can use some helpful method with your Route
, click here to know more about the Route Helpers
Laravel Migrate Fresh Command
There is a new feature added with migrate:
namespace in Laravel 5.5.
Before Laravel 5.5, You were using the migrate:refresh
command to roll back your existing migrations but with the new release of Laravel 5.5, There is an improvement with migrate:fresh
command that drops all the table and then migrate it from start.
By running migrate:refresh
command, You will see the following output on your terminal :
$ php artisan migrate:refresh
Output :
Rolling back: 2014_10_12_100000_create_password_resets_table Rolled back: 2014_10_12_100000_create_password_resets_table Rolling back: 2014_10_12_000000_create_users_table Rolled back: 2014_10_12_000000_create_users_table Migrating: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_000000_create_users_table Migrating: 2014_10_12_100000_create_password_resets_table Migrated: 2014_10_12_100000_create_password_resets_table
Now run the migrate:fresh
command and see the output :
$ php artisan migrate:fresh
Output :
Dropped all tables successfully. Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_000000_create_users_table Migrating: 2014_10_12_100000_create_password_resets_table Migrated: 2014_10_12_100000_create_password_resets_table
Support for Email Themes in Mailable
Laravel 5.4 offers Markdown emails that provide a default theme to compose emails in Markdown, but with the release of Laravel 5.5, There is much more flexibility to use email theme directly in the Mailable class.
You will have to write your styles in .css
file to use custom theme for a specific mailable.
touch resources/views/vendor/mail/html/themes/custom.css
Now you can specify a $theme
property in the Mailable class :
- class SendNotification extends Mailable
- {
- protected $theme='custom';
- [...]
- }
class SendNotification extends Mailable { protected $theme = 'custom'; [...] }
In this short article, I highlight the some of new features of Laravel 5.5 with examples.
Click here to see the features of previous version of Laravel : New Feature in Laravel 5.3
Hope this code and post will helped you for implement What are the new features in Laravel 5.5. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs