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. However, updating a project developed in Laravel from one version to another is not as complicated as it seems. 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.
Before doing any update step, we must confirm that our application can be updated to Laravel 6.0 or not.
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.
So, let’s start exploring what are those changes… and few are listed below:
Let’s see all these new upgradations one by one…
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
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
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/
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) {
//
}
Now you can define your table primary key as a string instead of an integer using below syntax.
protected $keyType = ‘string’;
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’]);
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();
}
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.
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.
Subscribe to our newsletter and learn about the latest digital trends.