What are accessors and mutators in laravel?
Accessors are a way to retrieve data from eloquent after doing some operation on the retrieved fields from the database. For example, if we need to combine the first and last names...
Laravel
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.
Example:
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.
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.
Sign in to join the discussion.
Accessors are a way to retrieve data from eloquent after doing some operation on the retrieved fields from the database. For example, if we need to combine the first and last names...
Eloquent is the ORM used to interact with the database using Model classes. It gives handy methods on class objects to make a query on the database. It can directly be used to ret...
Session1. Retrieving Data from sessionsession()->get('key');2. Retrieving All session datasession()->all();3. Remove data from sessionsession()->forget('key'); or session()->flush(...
Subscribe for technical articles from iTechOrbit.