New features and changes in Laravel 5.4

New features and changes in Laravel 5.4

New features and changes in Laravel 5.4

Laravel 5.4 was released on Jan 24, 2017 with lot's of new features and improvements such as Sanitizing Middleware,Higher order messages,From Elixir to Mix,Fluent Routing,Components and Slots,Real-Time Facades,Laravel dusk etc.

As we know, Laravel is one of the most popular framework for PHP developer and it continues the improvements in their versions so we can say it's that time of year again Laravel came with new version from 5.3 to 5.4

Kindly have a look on official changes in Laravel 5.4

Request Sanitization Middleware

There are two new middleware added in the default middleware stack in Laravel 5.4 :

  • TrimStrings Middleware will automatically trim/remove all white spaces comes with request data that means when you add extra spaces in your form field then it remove those white spaces automatically.
  • Here is example where you will see if you remove TrimStrings Middleware then it will return you response with extra white spaces and if you add TrimStrings Middleware then it remove extra white spaces from request data.

    Without TrimStrings Middleware :
    dd(request('title'));
    // 'Expertphp.in '
    
    With TrimStrings Middleware :
    dd(request('title'));
    // 'Expertphp.in'
    
  • ConvertEmptyStringsToNull Middleware will automatically convert all empty string to null value that means any field of form is empty or embeded with empty string then it convert back to null value.
  • Here is simple example for ConvertEmptyStringsToNull Middleware.

    Let's assume i have a text input field that take title of project :

    
    

    If i do not use ConvertEmptyStringsToNull Middleware and i left text field blank then response will be :

    dd(request('title'));
    // ''
    

    If i use ConvertEmptyStringsToNull Middleware then this will now return null :

    dd(request('title'));
    // null
    
Blade Components and Slots

In Laravel 5.4, there is new features added with Blade template called @component directive.

Blade Components and Slots features are similar to sections and layouts.The features are desgined to provide you more flexibility in your blade templates.

You can use this features for those components that will be reusable throughout your application.

Example :

Let's have a example for showing an alert message :

  1. <!-- /resources/views/message.blade.php -->
  2. <div class="alert">
  3. {{ $slot }}
  4. </div>

Now you can inject it into your template like this :

  1. @component('message')
  2. Your message
  3. @endcomponent
The whereKey method

The whereKey method is new feature added in Laravel 5.4. The whereKey($id) method is used add dynamically where clause for given primary key to find record.

You can click here to know more about whereKey method in details with example.

laravel 5.4 New Features - The whereKey method with example

Phone: (+91) 8800417876
Noida, 201301