36 questions
3
votes
1
answer
76
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
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 ...............................
5
votes
2
answers
13k
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 ...
1
vote
0
answers
315
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 ...
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
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 ...
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.
...
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 ...
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' => ...
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
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 ...
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 ...
1
vote
0
answers
357
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, ...
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 ...
0
votes
1
answer
321
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 ...
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.
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 ...
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 ...