Questions tagged [laravel-service-container]
32 questions
10
votes
2 answers
Laravel Service Container and Service Provider
Need to understand Laravel service container and service provider through an example.

Ravinesh
- 119
- 1
- 1
- 3
4
votes
2 answers
Laravel - difference between singleton and instance binding in service container
In the service container of Laravel, I can bind both singleton and instance. From the Laravel doc:
Binding A Singleton
The singleton method binds a class or interface into the container that should only be resolved one time. Once a singleton…

Istiaque Ahmed
- 6,072
- 24
- 75
- 141
3
votes
2 answers
How to use tagging in Laravel's service container?
I need to know what is the purpose of using service container's tagging and how to use it by example this is what I have tried so far.
class MemoryReport
{
}
class SpeedReport
{
}
class ReportAggregator
{
public function…

Mohamed Azzam
- 33
- 6
3
votes
1 answer
Laravel Service provider and Service Container
In Laravel to access query, we use DB facades
DB::select()
from alanstorm website http://alanstorm.com/binding_objects_as_laravel_services I learned that DB facade use callstatic method that lead to DB::app['db']->select(). app is the Laravel…

Jsnow
- 375
- 1
- 6
- 14
2
votes
3 answers
How to bind .env values in Laravel Service using Service Container and Service Provider
What I want to achieve is I have a service class name 'SmsService'

Shahrukh
- 399
- 2
- 15
2
votes
1 answer
Bound class not resolving in package
I have an API class that is being bound into the container via a service provider:
public function register()
{
$this->app->bind('apiclient', fn($app) => new APIClient($app));
}
It is not defined as a package in 'app/config/app.php' as it is in…

ConBran
- 369
- 2
- 15
2
votes
0 answers
Define gates in custom service provider
I got a question. Is it best practice to define gates in custom service providers? I am writing a permission system in Laravel by defining gates for each permission. I created a custom service provider that boots a singleton service that manages the…

Dennis
- 21
- 1
1
vote
0 answers
Best way to override single method in Illuminate\Foundation\Application through service provider
I just made changes to the application structure for my Laravel application. It works well when runnning tests (for the Http controllers). The problem is when i try to run artisan commands (that literally need to access "getNamespace()" method), it…

Azvya Erstevan
- 115
- 8
1
vote
2 answers
Why I can not call Implementation method from library class?
In laravel 9 app I created class app/Implementations/LocalStorageUploadedFileManagement.php :

mstdmstd
- 2,195
- 17
- 63
- 140
1
vote
1 answer
Laravel Dynamic Filesystem Configuration Set in Controller Level
I'm trying to set filesystem configuration value dynamically in controller level. (I think it's almost impossible).
For example:
'sftp' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
'port' =>…

LoveCoding
- 1,121
- 2
- 12
- 33
1
vote
0 answers
How to Switch Dependency Based on the Request in Laravel Using Dependency Injection?
I want to switch the payment gateway based on the user's request. I don't want multiple endpoints for each gateway, so i'm trying write one endpoint that handles multiple payment gateways. With that, I also want the controller __construct method to…

Chris
- 4,643
- 6
- 31
- 49
1
vote
0 answers
In what file does the binding of request key to the service container of Request Facade happen in laravel?
In the laravel Request facade we have the key 'request' being returned. To my understanding this is the key that is bound to the service container to resolve a class. In which file do we have the binding logic of the key happening?

Alphy Gacheru
- 489
- 1
- 9
- 28
1
vote
1 answer
What is Laravel Service Container?
I read this documentation about Service Container and also some other information on youtube but still not fully understand what is Service Container and how or when to use it so please if you can explain in simple words what is Service Container…

zac
- 4,495
- 15
- 62
- 127
0
votes
0 answers
How can I use laravel service containers to run heavy tasks?
My question is: How can I use laravel service containers to do heavy tasks. Actually I would like to use service containers to increase the performance.
Suppose we have the below class:
class HeavyTask
{
public function doHeavyTasks(){
…

farhad.a
- 341
- 4
- 17
0
votes
0 answers
How to bind objects to specific parameters (not types) in Laravel's service container
Context: From a Laravel service container, we can easily bind abstracts to concrete implementations, and variables to scalar types, using the following, respectively:
// Abstracts to concrete…

exastris
- 23
- 5