php – 禁用laravel 5.2中特定路由的Web中间件

我想访客用户可以访问主页但在内置身份验证过程中laravel重定向登录页面.我怎样才能让访客用户访问主页? @H_403_1@我的routes.PHP

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

Route::get('/','HomeController@index');

Route::get('/insert','HomeController@insertform');
Route::get('/job/{id}','JobsController@show');

Route::get('/city/{city}','JobsController@city');

Route::post('/insert','HomeController@insert');
Route::get('/cityinsert','HomeController@cityinsert');
Route::post('/cityinsert','HomeController@cityinsertpost');

});
@H_403_1@和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);
}
}
@H_403_1@这是我的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,];
}
从HomeController构造中删除中间件:
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //$this->middleware('auth');
    }
}

相关文章

[laravel] laravel的数据库配置 找到程序目录结构下.env文件 配置基本的数据库连接信息 DB_HOST=127.0....
[Laravel] Laravel的基本HTTP路由 使用Laravel的基本路由,实现get请求响应,找到文件app/Http/routes....
如果说laravel框架的核心是什么,那么无疑是服务容器。理解服务容器的概念,对于我们使用laravel太重要...
网上有很多解析laravel中间件的实现原理,但是不知道有没有读者在读的时候不明白,作者是怎么想到要用a...
laraveli添加一个或多个用户表,以admin为例。 部分文件内容可能需要根据实际情况修改 创建一个Admin模...
TL;DR: 本文介绍 Laravel 的 FastExcel 组件,文中会对 PHP generators 速览,并给出如何在节约内存的同...