You wouldn't inject a Service Provider, that isn't what they're for
https://laracasts.com/series/laravel-from-scratch-2017/episodes/25
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I started with
php artisan make:provider CartServiceProvider
Then I added to config\app.php, inside providers array this
App\Providers\CartServiceProvider::class,
This is the full actual code , comment striped out and compacted to a betetr reading, of the provider itself.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class CartServiceProvider extends ServiceProvider
{
public function boot() { }
public function register() { }
public function test()
{
return "Cart Service is working";
}
}
I'm trying now to use it into one of my controller. I added
use App\Providers\CartServiceProvider;
Then into one of the controller action I tried to inject the provider
public function index(CartServiceProvider $cart)
{
return view('customer_area.dashboard')
->with('cart', $cart);
}
I don't have modified yet the view.
Problem
When I access to index action of this controller, I got the exception
Unresolvable dependency resolving [Parameter #0 [ $app ]] in class Illuminate\Support\ServiceProvider
This is now obscure for me how to fix this....
You wouldn't inject a Service Provider, that isn't what they're for
https://laracasts.com/series/laravel-from-scratch-2017/episodes/25
Please or to participate in this conversation.