Archive for the ‘All Category’ Category

1. Implementation of Type Declarations

The type declaration is used to specify the type of variable. PHP sets this automatically and because of which, PHP is a weakly typed language. PHP does not need you to declare the data type. Because of which, you could do radical things with the variables, like adding Float into String without resulting in an error. Type declaration helps you get the expected results. Making sure that only certain procedures can occur. Which makes the code understandable.

In the previous PHP versions, we could use type hinting method. This method specifies the type of an argument declaration in a function. But the issue with this method was that you can only use it with a function declaration. Which limits to only two types, a class name, and an array.

Scalar Type Declaration

PHP 7 has now added Scalar type declaration for int, float, string, and boolean. Adding scalar type declaration and enabling strict requirements ensures that more correct and well-documented PHP programs can be written. It also helps you in gaining more control over your code and make the code easier to read.

By default, on PHP 7, these declarations are non-strict. Which means that the type forging is possible. As if you pass a string starting with a number into a float type function, it grabs the number from in the start and skips everything else. Passing a float into a function that requires an int, that float will become int.


function getSum(float $a, float $b) {
   return $a $b;
getSum(6, "7 week");
//Here int(6) changed to float(6.0) and string “7 week” changed to float(7.0)
//with a “Notice: A non well formed numeric value encountered”
//returns float(13)
getSum(1.1, "2.2");
//Here string "2.2" is changed to float(2.2) without any notice
//returns float(3.3)
getSum(3.1, 2);
// changes int(2) to float(2.0)
// returns int(5.1)

2. Speed Improvement

The developers for the PHP 7 has done a pretty commendable job here. Now your PHP codebase uses less memory and gives you even more performance than before. After it’s release, internet was overloaded with benchmarks which were really promising. It is almost a 2x increase inserver response times with PHP 7. For further details on benchmarks click here.



Nullable Types

With the introduction of Nullable Types, you can now return null from a function. This feature was already well supported in other languages including C# and Java. Nullable types are illustrated in the following example:

Void Function

The much awaited void function has been included inside PHP 7.1. You can now set void as the return type for your functions. For instance:

Symmetric Array Destructuring

In PHP 7.1, array syntax ([ ]) can be used to destructure arrays for assignment. This is an excellent alternate to list() syntax (which is also available). This structure can be used in a foreach statement for assignment. For instance:

Class Constant Visibility

You can now use access modifiers with a constant variable within the class to handle its visibility across the project. For instance:

Iterable Pseudo-type

PHP 7.1 has introduced a new pseudo-type that is similar to callable. It can be used in parameter and return type. It accepts either, arrays or objects, that implement Traversable interface. For instance:

Multi Catch Exception Handling

With the introduction of Multi Catch exception you can now catch more than one exceptions at a time in a single catch. For instance:

Support for Keys In list()

You can now specify keys while creating a list using list() function or using new shorthand syntax, i.e. ([ ]). For instance:

Support for Negative String Offsets

You now use negative offsets for string manipulation or can index it with ([ ]) or ({ }). Also, you can use simple variable parsing syntax inside string. For instance:

Convert Callables to Closures

PHP 7.1 will have a new static method Closure::fromCallable() within the Closure class to convert callables to Closure object. For instance:

Asynchronous Signal Handling

To reduce overhead using ticks, a new function pcntl_async_signals() has been introduced to enable asynchronous signal handling directly. For instance:


This version comes with a host of improvements and builds on the successes of the previous versions. In this article, I will discuss the major highlights of Laravel 5.6, particularly

  1. New Blade Directives
  2. Logging Improvements
  3. Single Server Task Scheduling
  4. Dynamic Rate Limiting
  5. Broadcast Channel Classes
  6. API Controller Generation
  7. Eloquent Date Casting
  8. Argon2 Password Hashing
  9. UUID Methods
  10. Bootstrap 4


Single server task scheduling

Another addition made to Laravel 5.6 is single server task scheduling, which allows the ability to limit a scheduled job to only execute on a single server. Before Laravel 5.6, If your application is running on multiple servers and the task scheduler is also running on these servers, then the scheduled tasks will run multiple times.

Now you can indicate that the task should run on only one server, by making use of the onOneServer() method:


To utilize this feature, your application must be using the memcachedor redis cache driver as your application’s default cache driver. In addition, all servers must be communicating with the same central cache server. For more information, check out the docs.

Dynamic rate limiting

Laravel has a throttle middleware that can be used to rate limit access to routes within your application. The middleware can be used as below:

    Route::get('/user', function () {
      return 'access granted!';

In the above example, we pass in the maximum number (10 in this case) of requests that can be made to the /user route and also the time in minutes (1 in this case) which the requests will span. As you can see, we are hard coding in these values. This is fine until, for example, you want to control access to the route base on the user’s privilege or something. Prior to Laravel 5.6, there is no way to easily achieve this.

With the addition of dynamic rate limiting in Laravel 5.6, we can now dynamically pass the number of requests to be made to the throttle middleware. To achieve the scenario above, we can have a rate_limit column on our users table, which will hold the number of requests a particular user can make. Then we can use it as below:

    Route::get('/user', function () {
      return 'access granted!';

Now any user access to the /user route will be determined by the value on the rate_limit column. Of course, how the value in the rate_limit column is determined will depend on your application. For more information, check out the docs.

Broadcast channel classes

Previously when broadcasting on a private channel, we have to define a Closure in the routes/channels.php file which is used to determine whether a user is logged in or not. This can easily become bulky depending on your application. So in Laravel 5.6, instead of using Closures to authorize channels, you may now use channel classes. We can make use of the new make:channel Artisan command to generate broadcast channel classes:

    $ php artisan make:channel ChatChannel

This will create a new ChatChannel channel class in the App/Broadcasting directory.

Next, we can register the channel in the routes/channels.php file:

    use App\Broadcasting\ChatChannel;

    Broadcast::channel('chat', ChatChannel::class);

Then we’ll define the authorization logic in the join() method of the ChatChannelchannel class. The join() method will contain the authorization logic that we would have typically placed in your channel authorization closure:


    namespace App\Broadcasting;

    use App\User;
    use Illuminate\Support\Facades\Auth;

    class ChatChannel
      * Create a new channel instance.
      * @return void
      public function __construct()

      * Authenticate the user's access to the channel.
      * @param  \App\User  $user
      * @return array|bool
      public function join(User $user)
        return Auth::check();

For more information, check out the docs.

Bootstrap 4

Bootstrap 4 has been officially released after over two years of it being in development. In this vein, all frontend scaffolding such as the authentication boilerplate, example Vue component and even the pagination link generation in Laravel have been upgraded to use Bootstrap 4.

If you are upgrading your application from Laravel 5.5, you can continue to use Bootstrap 3 by adding the line of code below to the boot() method of app/Providers/AppServiceProvider:

    public function boot ()

This will allow your application to use Bootstrap 3 as the default styling for pagination links.

Argon2 password hashing

With the release of PHP 7.2, which supports argon2 password hashing, Laravel now supports password hashing via the Argon2 algorithm. A new config/hashing.phpconfiguration file is now being shipped with Laravel, which can be used to configure the default hash driver for your application.

However, to use argon2 password hashing, your application must be running on PHP 7.2.0 and above.

API controller generation

Laravel 5.6 makes it much easier to build APIs with Laravel. It introduces a new --apiswitch to the make:controller Artisan command:

    $ php artisan make:controller API/BookController --api

This will generate BookController with only the methods (indexstoreupdate and destroy) needed when building APIs. This prevents having create() and edit()littering around or having to manually delete them yourself, since they are not useful when building APIs.

This introduction, combined with the apiResource() while defining resourceful routes, means awesome experience building API with Laravel. To learn how to combine these features together with API resources, see my other tutorial on [Build robust API with Laravel API Resources].

Logging improvements

Logging in Laravel has become a lot better with the release of Laravel 5.6. The logging system now has it own dedicated config/logging.php configuration file. You can now easily build logging stacks that send log messages to multiple handlers.

    'channels' => [
      'stack' => [
        'driver' => 'stack',
        'channels' => ['syslog', 'slack'],
      'syslog' => [
        'driver' => 'syslog',
        'level' => 'debug',
      'slack' => [
        'driver' => 'slack',
        'url' => env('LOG_SLACK_WEBHOOK_URL'),
        'username' => 'Laravel Log',
        'emoji' => ':boom:',
        'level' => 'critical',

From the config file above, we are stacking multiple channels (syslog and slack) so that all debug level messages will be sent to the system log while all error level messages be sent to Slack so that your team can quickly react to errors.

It is also now easier to customize existing log channels using the logging system’s new tap functionality. For more information, check out the docs.

Model serialization improvements

Prior to Laravel 5.6, queued models would not be restored with their loaded relationships intact. With the improvement to Laravel 5.6, now relationships that were loaded on the model when it was queued are automatically re-loaded when the job is processed by the queue.

Eloquent date casting

It’s now possible to individually customize the format of Eloquent date cast columns:

    protected $casts = [
      'birthday' => 'date:Y-m-d',
      'last_seen_at' => 'datetime:Y-m-d H:00',

We simply specify the desired date format within the cast declaration. Now this format will be used when serializing the model to an array or JSON.

Blade component aliases

Another new feature in Laravel 5.6 is Blade component aliases. You can now alias your Blade components stored in a sub-directory for easier access. Let’s say, for instance, we have a Blade component that is stored at resources/views/components/notification.blade.php. We can use the componentmethod to alias the component from components.notification to notification:

    Blade::component('components.notification', 'notification');

Then we can render it using a directive:

    @notification('notification', ['type' => 'danger'])
      Your account has been successfully upgraded!

    // we can even omit the component parameters if it has no additional slots
      Your account has been successfully upgraded!

For more information, check out the docs.

UUID methods

Laravel 5.6 introduces two new methods for generating UUIDs: Str::uuid and Str::orderedUuid:

    use Illuminate\Support\Str;

    $uuidString = (string) Str::uuid();

    $orderedUuidString = (string) Str::orderedUuid();

The orderedUuid method will generate a timestamp-first UUID that is more easily and efficiently indexed by databases such as MySQL. Each of these methods returns a Ramsey\Uuid\Uuid.


Laravel 5.6 applications now contain a dev composer dependency for a package called Collision, which is a community package developed and maintained by Nuno Maduro. Collision is a detailed and intuitive error handler framework for console/command-line PHP applications.

This packages provides beautiful error reporting when interacting with your Laravel application on the command line:


  • Laravel 5.6 requires PHP 7.1.3 and above.
  • The Artisan optimize command was deprecated as of 5.5 and has been removed officially from 5.6.
  • Laravel 5.6 includes two new Blade directives: @csrf and @method.

You can view the complete change logs on GitHub.




sitemanager.xml file open and update your backup file….