Using contracts resolved in AppServiceProvider
I am trying to use a contract which is resolved in the AppServiceProvider, in the Filament\AdminPanelProvider panel config. But it is not resolved at this point as Filament\AdminPanelProvider seems to be registered first, even though it appears after the main provider in the config/app.php How can I change this order?
14 Replies
Can you share an example of what you're trying to do?
$this->app->make(MyContract::class) inside the panel() method fails because MyContract::class can't be resolved… Not sure what else I can say.
What is the use of MyContract::class... what are you using it for?
Shouldn't it be
$this->app->make(ColourContract::class)
instead of Colour::class
?Yes, that's what I have tried. ColourContract is an alias. Sorry, I just undid my deletion of the code.
@trovster Not sure... but have you tried
bootUsing
?
I think you'll have all bindings available in the boot phaseIs your
$this->app->singleton()
placed in the boot()
method or in the register()
method?Solution
It is in the
boot()
method.OK, so then you should move it to the
register
method
Laravel makes the difference specifically, so that you can register all singletons and contracts in the register method, and then in the boot()
method you can trust Laravel that all these singletons and contracts have been registeredPerfect, thanks 🙂
i've just tried your suggestion but the colors doens't change. any ideas?
If I remember correctly,
bootUsing()
might be too late in the process... I'll see if I can find you another reference
This one is using FilamentColor
from AppServiceProvider
:
https://discord.com/channels/883083792112300104/1150491658044051606/1150531056680829049perfect, thanks a lot!