php - Laravel 5.5 require auth in staging -


i have project few packages have routes. have staging/demo environment needs publicly accessible.

is there way require auth middleware (or similar) routes without putting on of individual routes , route groups? (thinking in bootstrap??)

if want middleware run during every http request application, list middleware class in $middleware property of app/http/kernel.php class.

protected $middleware = [     \illuminate\foundation\http\middleware\checkformaintenancemode::class,     \illuminate\foundation\http\middleware\validatepostsize::class,     \app\http\middleware\trimstrings::class,     \illuminate\foundation\http\middleware\convertemptystringstonull::class,     \app\http\middleware\trustproxies::class,     middleware::class, ]; 

if not have access, or not want, modify package controllers, can create middleware (recommend inheriting authenticatesession. example:

<?php  namespace app\http\middleware;  use illuminate\session\middleware\authenticatesession;  use auth; use closure;  class authenticateifenvironment extends authenticatesession {     public function handle($request, closure $next)     {         if (env('app_env') == 'xxxxxxxx' && !auth::user() && !$request->is('login')) {             return redirect('/login');         }         return parent::handle($request, $next);     } } 

then kernal.php looks this:

protected $middleware = [     \illuminate\foundation\http\middleware\checkformaintenancemode::class,     \illuminate\foundation\http\middleware\validatepostsize::class,     \app\http\middleware\trimstrings::class,     \illuminate\foundation\http\middleware\convertemptystringstonull::class,     \app\http\middleware\trustproxies::class,     \app\http\middleware\authenticateifenvironment::class, ]; 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -