Laravel 5.8 New Features List
PHP laravel introduce new version laravel 5.8 with new features. Today laravel 5.8 is released and available for all. laravel 5.8 added new feature like cache TTL changes and lock, Deprecate string and array helper methods, update email validation, Automatic Policy Resolution, PHP dotenv, added firstWhere function in collection, database mysql json value etc.
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.
*) 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);
*) Added 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 '[email protected]' then it consider invalid but now it consider valid.
*) Added 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...
- How to create and download pdf in Laravel 5.8?
- Ajax Autocomplete Textbox in Laravel 5.8 Example
- Laravel 5.8 CRUD (Create Read Update Delete) Tutorial For Beginners
- PHP Laravel 5.7 - Create Admin Panel Example
- Laravel - Comment System Tutorial from Scratch
- Laravel 5.7 Import Export Excel to database Example