X
    Categories: Laravel

Whats new in laravel 5.5?

Whats new in laravel 5.5?

Whats new in laravel 5.5?. Laravel 5.5. going to release in July of 2017. Laravel 5.5 have few updates from laravel 5.4. Lets see what are the additions are added in laravel 5.5

Whoops is coming back

Whoops is used to handle the error which was built in with laravel 4 and later it was removed in laravel 5.5. Its come with new advanced features. Now laravel whoops screen will list out all errors, and By clicking the error name you can find out the exact error place mentioned.

Fresh Migration

In previous versions we have artisan command called

php artisan migrate:refresh

It will rollback all migrations and  re-migrate it again.

Now laravel 5.5 introduces new artisan command called

php artisan migrate:fresh

It will drop all tables and re-run all migrations. 

Assets preset

Laravel 5.5 have introduced new artisan command called

php artisan preset <type>

Which is used to swap the scaffoldings.

In default we have installed with bootstarp, vue in front end assets directory. By using preset command we can swap it.

Under php artisan command we can see new command called preset.

run php artisan help preset

There you can find out how to use preset in artisan command and what are the preset types are available to swap.


Example 1 => It Will strip everything and just will keep basic scaffoldings under front end assets directory.

php artisan preset none

Example 2 => It Will swap the application to vue, and you can find vue components under resources/assets folder.

php artisan preset vue

Example 3 => It Will swap the application to react, and you can find react components under resources/assets folder.

php artisan preset react

Example 4 => It Will swap the application to bootstrap, and you can find bootstrap components under resources/assets folder

php artisan preset bootstrap

Automatic package discovery

Till date, Once you install any package, you need to register Service provider and Alias at app.php Instead, Now we can add Service provider and Alias at Package composer.json itself. So while installing package it will detect it automatically and register it.

How to add service provider and alias in composer.json file :

"extra": {
        "laravel": {
            "providers": [
                "****\\****\\****"
            ],
            "aliases": {
                "****": "****\\****\\****"
            }
        }
    }

 Note  : You should not do it in your laravel composer.json, It should be added in package.json file.

Test your Email layout in browser

By using below command we can create a mail,

php artisan make:mail Welcome --markdown=emails.wecome

You can see Welcome Mail under mail folder and template at views emails folder.

Now write a route :

Route::get('test', function() {
  	return App\Mail\Wecome;
  })

and run your route in browser. You can see your email layout at browser. There you can debug it easily

Easy custom validation rules

Run :

php artisan

You can find new artisan command called make:rule => Which will help you to make a new validation rule.

  Run => php artisan make:rule CheckLessThanFive

It will create CheckLessThanFive.php under Rules folder. Under passes() function you can write your own validation rule.

for eg : return $value < 5;

public function passes($attributes, $value) {
return $value < 5;
}

How to use this in your controller validation rule area

 [
  'age' => new App\Rules\CheckLessThanFive
  ]

Collection Dumping

Normally we will use dump() or dd() to print the data at the end of scope.

for eg :

$post = Post::all()->shuffle()->isActive();

dd($post)

Now in laravel 5.5 we can dump at any place.

for eg :

Post::all()
	->dump()
	->shuffle()
	->dump()
	->isActive()
	->dump();

It will dump the data in each steps.

Factory Generation

Till date we have a only one Factory under database folder to create a fake users. Like that we can now make a multiple Factories based on Model name

for eg : php artisan make:factory Post

It will create PostFactory.php file under factories folder. The you can fill up your table fields and by running tinker command can create fake posts

php artisan tinker
>> factory('App\Post', 5)->create()

Custom Blade “If” Directives

My if condition at blade :

@if Auth::user()->isAdmin
	<p>You are admin</p>
@else
	<p>You are not admin</p>
@endif

Now we are going to customise if condition :

@isAdmin
	<p>You are admin</p>
@else
	<p>You are not admin</p>
@endif

To make this custom directive possible, you need to write it in your AppServiceProvider.php => boot() function

\Blade::if('isAdmin', function() {
return Auth::user()->isAdmin;
})


you can pass param also :

\Blade::if('isAdmin', function($param) {
return Auth::user()->isAdmin;
})

 

Marimuthu: