In Laravel, a closure is an anonymous function that often used as callback methods. Developers can also use it as a parameter in a function.

BY Best Interview Question ON 25 Jun 2020

Example

function handle(Closure $closure) {
    $closure();
}

handle(function(){
    echo ‘Best Interview Question’;
});

We can start by adding a Closure parameter to the handle method. This will be used as type hint us that the handle method takes a Closure.

We can call the handle method and pass a service as a parameter.

By using $closure(); in the handle method we tell Laravel to execute the given Closure which will then display ‘Best Interview Question.’