Explain Extending Bindings in Laravel And where to extend the bind in laravel

0 votes
Hii team,
Can anyone explain me the concept of extend binding? and what to extend the Laravel cache facility which is used to bind a custom driver resolver to the manager?
Thank you!
Mar 26, 2020 in Laravel by kartik
• 37,510 points
1,478 views

1 answer to this question.

0 votes

Hii,

 The extend method allows the modification of resolved services

For example, when a service is resolved, you may run additional code to decorate or configure the service. The extend method accepts a Closure, which should return the modified service, as its only argument:

$this->app->extend(Service::class, function($service) {
return new DecoratedService($service);
});

The above code will help you to modify the already resolved services.

To extend the Laravel cache facility, we will use the extend method on the CacheManager, which is used to bind a custom driver resolver to the manager, and is common across all manager classes. For example, to register a new cache driver named "mongo", we would do the following:

Cache::extend('mongo', function($app)
{
    // Return Illuminate\Cache\Repository instance...
});

Thank you!

answered Mar 26, 2020 by Niroj
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

Explain validations in laravel and How to validate my application incoming data?

Hey @kartik, In Programming validations are a handy ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
1,083 views
0 votes
1 answer

How to select year and month from the created_at attributes of database table in laravel 5.1?

Hello @kartik, There are date helpers available in ...READ MORE

answered Sep 30, 2020 in Laravel by Niroj
• 82,880 points
14,274 views
0 votes
1 answer
0 votes
1 answer

What is the significant difference between insert() and insertGetId() function in Laravel?

Hello, Insert(): This function is simply used to ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
2,485 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,905 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,690 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,560 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,884 views
0 votes
1 answer

Explain the concept of encryption and decryption in Laravel?

It is a process of transforming any ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,029 views
0 votes
1 answer

Explain make Method in Laravel and what does the make() method do in Laravel?

Hey, You may use the make method to ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,880 points
4,674 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP