36 questions
3
votes
1
answer
84
views
Laravel Service Container: Am I doing the right thing?
I have an invokable action class called: AttachMembersToRoom . Now, aside from basic form request validations, I also have complex validation, like comparing values across members, identify ...
0
votes
0
answers
250
views
How to Inject Services into a Queued Event Listener using Laravel 7?
I'm using Laravel 7. would like like to inject services into a event listener. Injecting their interfaces through the constructor works fine, but when I add "implements ShouldQueue" to the ...
0
votes
1
answer
123
views
Laravel Resource route is not holding any parameter on route list
GET|HEAD blogs ..................................................................................... blog.index › Blog\BlogController@index
POST blogs ...............................
0
votes
1
answer
186
views
Laravel Service Container zero configuration resolution automatic injection failure
I just recently started learning Laravel and decided to dive in learning by doing.
As far as i understand from documentation [example:1] [example:2] i can typehint properties in constructors for ...
5
votes
2
answers
14k
views
How to publish service provider to the application in laravel 11
I want to add service provider in laravel 11, but i am not sure how to add it using laravel 11. As previous version of laravel, it is added in config/app.php file, but in laravel 11 it needs to be ...
0
votes
0
answers
69
views
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 ...
1
vote
0
answers
316
views
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 ...
0
votes
1
answer
772
views
How does Service Container know when a constructor is triggered to resolve its dependencies?
For example I have a class named User and in its constructor I have a dependency named MyDependency.
MyDependency does not have any dependencies itself so I don't need to bind it to he $app container.
...
1
vote
0
answers
164
views
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 ...
0
votes
2
answers
1k
views
How can I mock a service class inside a Laravel Job?
I want to mock a service who call a third party, but I can't figure it out.
I have a controller method who has a service injected on it and do stuff:
public function store(Request $request, MyService $...
0
votes
0
answers
134
views
Executing my function before loading of kernel (Laravel)
Would like to build in a simple validation for the value of the APP_ENV parameter in my Laravel application. I want the parameter to be either dev, tst, acc or prd. If it's not one of these, my ...
1
vote
1
answer
453
views
Where to switch to other service depending on logged user field?
In laravel 9 app I try to switch to different service
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public ...
0
votes
1
answer
81
views
Service Provider not Resolving a registration: Target [App\\Services\\Payment\\Contracts\\PaymentService] is not instantiable
I have an interface that I wish to resolve on controllers. On registration inside a service provider, I am binding a class to the Service on condition.
Here is my service interface and two classes.
...
1
vote
2
answers
226
views
Why I can not call Implementation method from library class?
In laravel 9 app I created class app/Implementations/LocalStorageUploadedFileManagement.php :
<?php
namespace App\Implementations;
use App\Interfaces\UploadedFileManagement;
...
use Intervention\...
0
votes
0
answers
425
views
Laravel Service won't register
Followed every step from laravel 9 manual, and my service will not register consistently. Don't quite know why but it suddenly breaks and I receive a Target class [thumbnail] does not existerror out ...
0
votes
2
answers
1k
views
How laravel's helper functions are available globally in every file?
I have just started exploring laravel but I have one confusion . I know how to create own custom function file and make it available globally using compose.json file but I was trying to figure out how ...
2
votes
1
answer
1k
views
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' => ...
0
votes
1
answer
222
views
Laravel Service VS Trait
Difference between service & trait in Laravel
Assume I have a class which handles image uploading on my application
Should I write it as service or trait ?
when i should use service and trait ?
4
votes
3
answers
2k
views
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'
<?php
namespace App\Services;
use App\Contracts\SmsServiceContract;
use App\Models\Student;
use Twilio\Rest\Client;
class ...
0
votes
0
answers
556
views
Laravel: How to register an own implementation of `DatabaseManager` and `Connection`
Due to debugging reasons (I am hunting down a very weird bug), I need to extend the Laravel classes Illuminate\Database\DatabaseManager, Illuminate\Database\Connection, and Illuminate\Database\Query\...
0
votes
2
answers
145
views
Difference between User::class and new User
I am using Laravel 8. I want to know the difference between new User() and User::class because I am having trouble while using new User().
Here is the scenario,
I have UserServices class in which I am ...
2
votes
1
answer
57
views
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 ...
3
votes
0
answers
263
views
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 ...
0
votes
1
answer
205
views
Inject array into Controller with Service Container
I want to provide some default settings to a controller when it is instantiated. My end goal is to provide a dummy object for testing which I can use with registerPaymentMethod on my controller To ...
1
vote
0
answers
358
views
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, ...
1
vote
0
answers
56
views
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 ...
0
votes
2
answers
2k
views
Laravel route resolve custom data type
I have the following routes in routes/api.php:
Route::get('items/{item}', function(Guid $item) {...});
Route::get('users/{user}', function(Guid $user) {...});
Since Guid is a custom type, how can I ...
6
votes
2
answers
4k
views
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 ...
0
votes
1
answer
324
views
Storing instances in Laravel Service Container that may be null
I'm attempting to store an instance of the current department in Laravels Service Container, however sometimes this department may be null.
The department itself is loaded from session and retrieved ...
4
votes
2
answers
4k
views
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 ...
9
votes
2
answers
20k
views
Laravel Service Container and Service Provider [closed]
Need to understand Laravel service container and service provider through an example.
-7
votes
1
answer
113
views
How laravel service provider and container work for each other?
I have a confusion in the Laravel service Provider and Laravel container. In Laravel, how do service providers and containers work? Please give me a suitable example on it.
1
vote
1
answer
859
views
What is Laravel Service Container? [duplicate]
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 ...
0
votes
1
answer
800
views
How to properly use Laravel Service Container?
Ok, I've watched the Laracast videos on the topic and also have read the documentation, still I miss the core point here. Let's say we have the following structure:
So I understood how to create a ...
3
votes
1
answer
3k
views
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 ...
5
votes
2
answers
12k
views
Laravel service provider gives "Target [Interface] is not instantiable" error
My error message:
Illuminate \ Container \ BindingResolutionException
Target [Project\Backend\Service\Validation\ValidableInterface] is not instantiable.
I understand that interfaces and abstract ...