In my app, I have registered service providers base on middleware. Here is the sample code
class DomesticFlightMiddleware{
public function handle($request, Closure $next)
{
app()->register('aunicaj\Providers\DomesticTravelServiceProvider');
}
}
on another middleware
class InternationalFlightMiddleware
{
public function handle($request, Closure $next)
{
app()->register('aunicaj\Providers\InternationalTravelServiceProvider');
}
}
This is working fine but when I execute php artisan route:list I get the following error
Target (Interface) is not Instantiable while building (Controller).
Are there any other way to conditionally register service providers?