why don't you just put the middleware as needed in your app and put your app.debug conditional inside the middleware itself? in other words, add your ClockworkServiceProvider middleware to all routes or whichever routes it would normally be added to and then inside your middleware do this:
public function handle($request, Closure $next)
{
if (config('app.debug'))
{
// do something
}
return $next($request);
}
this would load your service provider and you could just insert it wherever you need in the kernel stack.
public function handle($request, Closure $next)
{
if (config('app.debug'))
{
\App::register('Clockwork\Support\Laravel\ClockworkServiceProvider');
}
return $next($request);
}
here's what i did for laravel 5.0.33. in the app\Http\Kernel.php.
public function bootstrap() {
parent::bootstrap(); // should have loaded environment detection now.
if ($this->app->environment() == 'local') {
$this->pushMiddleware('Clockwork\Support\Laravel\ClockworkMiddleware');
}
}
I use the AppServiceProvider I check the env and only load the service provider then I would not use the prependMiddleware method.
public function register()
{
$this->app->bind(
'Illuminate\Contracts\Auth\Registrar',
'App\Services\Registrar'
);
// if in dev mode then enable some dev tool service providers
if ($this->app->environment() == 'local' or 'testing') {
$this->app->register('Laracasts\Generators\GeneratorsServiceProvider');
$this->app->register('Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider');
// $loader = AliasLoader::getInstance();
$this->app->register('Barryvdh\Debugbar\ServiceProvider');
$loader = AliasLoader::getInstance();
$loader->alias('Debugbar', 'Barryvdh\Debugbar\Facade');
// $this->app->register('Clockwork\Support\Laravel\ClockworkServiceProvider');
// $loader->alias('Clockwork', 'Clockwork\Support\Laravel\Facade');
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community