In this tutorial, we will talk about new feature an updates of laravel new version laravel 5.8. i will list of what's new features and upgrade point. We will discuss some of the noticeable changes and some of the new additions to the Laravel 5.8 family.
we will see list of main changes in this tutorial about what's new in laravel 5.8 version.
Let's see one by one important updates on laravel 5.8 version. that will help to use in your next project. laravel 5.8 does not change directory structure, so don't worry about that. let's see bellow list.
You can see the list topic of new changes.
- Deprecated String and Array Helpers Functions
- Blade Template File Path in Compiled file
- Cache TTL in Seconds Change
- Update Email Validation Rule
- New Method firstWhere in Collection
- Unquoted MySQL JSON Values in Database
Deprecated String and Array Helpers Functions
In my point of view, removing all string and array global functions in laravel 5.8. you can not use any more functions like array_add, array_first, array_last, str_slug, str_random etc, instead of this functions you can use same method using Illuminate\Support\Arr and Illuminate\Support\Str facade like as bellow example.
$array = Arr::add(['name' => 'Hardik'], 'price', 200);
// ['name' => 'Hardik', 'price' => 200]
$random = Str::random(10);
Blade Template File Path in Compiled file
As we know laravel compile blade file, but as you can see your laravel 5.7 or laravel 5.6 Compiled blade files there are no file path of complied.
In laravel 5.8 they provide path of blade template file path as shown in example:
<?php /* /var/www/me/5.8/blog/resources/views/welcome.blade.php */ ?>
<html lang="<?php echo e(str_replace('_', '-', app()->getLocale())); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
Cache TTL in Seconds Change
Laravel 5.8 update cache time in ttl in minutes into seconds. so basically, you need to add time in seconds in put(), putMany(), add() and remember().
You can see bellow example to how to set time like as bellow example:
Cache::put('hd', 'hardik', now()->addSeconds(60));
Update Email Validation Rule
In this feature, laravel 5.8 updated email validation rule. laravel had already email validation, but in this validation they update feature.
The email validation rule now checks if the email is RFC5630 compliant rules.
before if you add 'firstname.lastname@example.org' then it consider invalid but now it consider valid.
New Method firstWhere in Collection
Laravel 5.8 added new function firstWhere() with collection object. you can get single object using firstWhere method instead of first().
Let's see example:
$collection = collect([
['name' => 'Hardik', 'age' => 25],
['name' => 'Vimal', 'age' => 24],
['name' => 'Harshad', 'age' => 23],
// ['name' => 'Vimal', 'age' => 24]
Unquoted MySQL JSON Values in Database
this feature for json datatype column supported only. the query builder will now return unquoted JSON values when using MySQL and MariaDB.
see bellow example:
$value = DB::table('products')->value('details->language');
// Laravel 5.8...
There are more new small small features added by laravel 5.8 but here is a most changes. i hope it can help you...
Do you like below Tutorials ?
- Laravel 5.7 Image Upload with Validation Example
- Laravel 5.7 get ip address
- Email Verification in laravel 5.7 Example
- Calculate age from date of birth in Laravel
- Get date on change event of Bootstrap Datepicker
- PHP Laravel 7.x and 6.x Union query Example