Tell me how do you do dependency injection in laravel?



Tell me how do you do dependency injection in laravel?..

Answer / Uttam Kumar

"Dependency Injection is accomplished in Laravel through the use of the service container. To bind a class as a service, you can utilize the IoC container with the `bind`, `singleton`, or `instance` methods. For example:nn<code>// Bind a class as a singletonn$app->singleton('AppServicesMyService', function () {n return new AppServicesMyService();n});</code>"

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Laravel PHP Framework Interview Questions

Write a code to upload a file in laravel 5?

1 Answers  


How to fetch data from database in laravel?

1 Answers  


How do I populate my database with sample data?

1 Answers  


What is composer lock in laravel?

1 Answers  


What do you understand by lumen?

1 Answers  


How to write php code in laravel blade?

1 Answers  


What is escape string?

1 Answers  


How do I seed my database for column that is a foreign key referencing to other table?

1 Answers  


What do you understand by eloquent orm?

1 Answers  


What are service providers in laravel?

1 Answers  


what is meant by Laravel - Contracts ?

2 Answers  


Is laravel good for ecommerce?

1 Answers  


Categories