2016-02-13 27 views
5

ゲストユーザがホームページにアクセスできますが、組み込みの認証プロセスでlaravelがログインページにリダイレクトします。ゲストユーザにホームページへのアクセス権を与えるにはどうすればいいですか?laravelの特定のルートのWebミドルウェアを無効にする5.2

私のroutes.php:

Route::group(['middleware' => 'web'], function() { 
Route::auth(); 

Route::get('/', '[email protected]'); 

Route::get('/insert', '[email protected]'); 
Route::get('/job/{id}', '[email protected]'); 

Route::get('/city/{city}', '[email protected]'); 

Route::post('/insert', '[email protected]'); 
Route::get('/cityinsert', '[email protected]'); 
Route::post('/cityinsert', '[email protected]'); 

}); 

class Authenticate 
{ 
/** 
* Handle an incoming request. 
* 
* @param \Illuminate\Http\Request $request 
* @param \Closure $next 
* @param string|null $guard 
* @return mixed 
*/ 
public function handle($request, Closure $next, $guard = null) 
{ 
    if (Auth::guard($guard)->guest()) { 
     if ($request->ajax()) { 
      return response('Unauthorized.', 401); 
     } else { 
      return redirect()->guest('login'); 
     } 
    } 

    return $next($request); 
} 
} 

をauthenticate.php、これは私のkernel.phpある

class Kernel extends HttpKernel 
{ 
/** 
* The application's global HTTP middleware stack. 
* 
* These middleware are run during every request to your application. 
* 
* @var array 
*/ 
protected $middleware = [ 
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, 
]; 

/** 
* The application's route middleware groups. 
* 
* @var array 
*/ 
protected $middlewareGroups = [ 
    'web' => [ 
     \App\Http\Middleware\EncryptCookies::class, 
     \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
     \Illuminate\Session\Middleware\StartSession::class, 
     \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
     \App\Http\Middleware\VerifyCsrfToken::class, 
    ], 

    'api' => [ 
     'throttle:60,1', 
    ], 
]; 

/** 
* The application's route middleware. 
* 
* These middleware may be assigned to groups or used individually. 
* 
* @var array 
*/ 
protected $routeMiddleware = [ 
    'auth' => \App\Http\Middleware\Authenticate::class, 
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 
]; 
} 
+0

以下のようなミドルウェアに関数名を渡す必要があります構築物に認証を免除する上記ルートの

Route::get('/', '[email protected]'); 

をミドルウェア宣言の例外を追加しますが、あなたのカーネルを表示します.phpも同様 –

+0

カーネルファイルを追加しました –

答えて

6

にHomeController構築物からミドルウェアを削除します。

class HomeController extends Controller 
{ 
    /** 
    * Create a new controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     //$this->middleware('auth'); 
    } 
} 
9

あなたは

class HomeController extends Controller 
{ 
    /** 
    * Create a new controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('auth', ['except' => 'index']); 
    } 
} 
+0

Ok on Laravel 5.2 –

+0

Ok on Laravel 5.5でも –

関連する問題