As developers, our job is not only to create applications that work but also to give them support so that they can be maintained throughout their useful life. In the case of Laravel, major updates that bring new features, improvements and corrections are made every 6 months.
In this article, we will tell you what are the most important changes and the steps to update your application from Laravel version 5.8 to 6.0.
Especially knowing that it will be an LTS version, that is, it will have support for corrections of security problems until September 2022.
What requirement we need for use of Lavarel 6.0 :
Before doing any update step, we must confirm that our application can be updated to Laravel 6.0 or not.
The version of the application to be updated is Laravel 5.8. Otherwise, you must update it to that version. Take into account that Laravel 5.9 does not exist due to the changes made to the versioning of the framework.
The production server and other environments must have PHP 7.2 or higher, as it is the new minimum requirement of Laravel 6.0 because PHP 7.1 will have active support until December 2019.
Since Laravel 6.0 announced, all need to confirm that each of the third-party packages used in the application can work with Laravel 6.0? To do this you should check their official pages or repositories.
Some recommendation
Use Git to avoid problems if something fails and you cannot solve, we recommend you create a new branch to update so that the code of your working project will be supported.
Default auth with ui:auth, make:auth Removed
Laravel team has removed default make:auth command and introduced new command which is ui:auth.
To use this package, first of all, you have to install it using the below command.
-
composer require laravel/ui
After installing this package you have now many commands to generate Ui code with authorization.
You can see all new commands using the below command.
-
php artisan ui –help
If you want to set the default as vue or react instead of bootstrap then use below command.
-
php artisan ui vue
-
php artisan ui react
Now you can make your default auth scaffolding using below command
-
php artisan ui:auth
If you want to generate only views then run below command.
-
php artisan ui:auth –views
String and Array Default Functions Removed and Moved to Package
Now there is no default helper function for array and string. All str_ and array_ helper functions have been removed and moved to a new package called helpers. You can install it in your project using the below command.
-
composer require laravel/helpers
Carbon 1.0 Removed and Supported Carbon 2.0
There is no support for carbon 1.x longer in Laravel 6 because now they have updated it to carbon 2.x. You can read it from here: https://carbon.nesbot.com/
Lazy Collection with New Cursor Method in Eloquent
Suppose you a very large dataset in your project and you want to iterate them with the condition then these will be time taking in Generator but using Lazy Collection you can do it with low memory consumption.
In the older version of Laravel return an instance of Generator, now it will return an instance of Lazy Collection.
$blogs = App\Blog::cursor();
foreach ($blogs as $blog) {
//
}
Primary Key Type Declaration in the Model
Now you can define your table primary key as a string instead of an integer using below syntax.
-
protected $keyType = ‘string’;
BelongsTo::update Method Update in Eloquent
Suppose you have two model attached via a belongsTo relationship and receive mass assignment then you can call update method direct on the model like below.
-
$comment->blog()->update([‘foo’ =>’bar’]);
-
$comment->blog->update([‘foo’ =>’bar’]);
Authorization Response
In older version of laravel it was very difficult to show custom error messages in default auth, but now there is new method Gate::inspect which provides the authorization responce.
$my_response = Gate::inspect(‘view’, $dashboard);
if ($my_response->allowed()) {
// User can see Dashboard…
}
if ($my_response->denied()) {
echo $my_response->message();
}
Input Facade Removed Permanently
In a very old version of Laravel, we have used the Input facade, which is work like Request facade. But now in a new will, it was removed permanently. Now if you wish to use Input::get method then you have to call it like Request::input method. All other calls to the input facade may simply be updated to use the Request facade.
Conclusion
Laravel is a fast, free and open-source PHP development framework. Whose main goal is to allow you to work in a structured and fast manner. Laravel takes the monotony of web development. It provides all the tools you need to get you started programming whatever you need, it’s built to be simple and easy to learn.