2016-02-13 21 views
5

Tôi muốn người dùng khách có quyền truy cập vào trang chủ nhưng trong quá trình xác thực được xây dựng trong quá trình chuyển hướng laravel đến trang đăng nhập. làm thế nào tôi có thể cung cấp cho người dùng khách truy cập vào trang chủ?tắt phần mềm trung gian trên web cho các tuyến đường cụ thể trong laravel 5.2

routes.php tôi:

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]'); 

}); 

và authenticate.php

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); 
} 
} 

và đây là kernel.php tôi

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

hiển thị kernel .php cũng –

+0

Tôi đã thêm tập tin hạt nhân –

Trả lời

6

Tháo middleware từ HomeController xây dựng:

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

Thêm một ngoại lệ trong việc kê khai middleware trong xây dựng

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

cho các tuyến đường trên để được miễn xác lập mà bạn phải vượt qua tên hàm cho middleware như dưới đây

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

Ok trên Laravel 5.2 –

+0

Ok trên Laravel 5.5 cũng –

Các vấn đề liên quan