search

Home  >  Q&A  >  body text

laravel session reading problem

As shown below:

在生成验证码的时候,将其存到session中,在验证的时候用Session::get 取不到值

我想大声告诉你我想大声告诉你2860 days ago537

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 16:52:13

    Usually this kind of problem is caused by not placing the routing under the web middleware

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-16 16:52:13

    protected $middlewareGroups = [
            //中间件web
            'web' => [
                \App\Http\Middleware\EncryptCookies::class,
                \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
                //看到这里了吗!StartSession!!!!要把路由放在这个中间件了才会启动Session!!
                \Illuminate\Session\Middleware\StartSession::class,
                \Illuminate\View\Middleware\ShareErrorsFromSession::class,
                \App\Http\Middleware\VerifyCsrfToken::class,
            ],
    
            'api' => [
                'throttle:60,1',
            ],
        ];
        
    
    Kernel.php
    ----------
    两种路由中间件写法各人喜好!
    Route::get('/', function () {
        //路由放在这里
    })->middleware('web');
    
    Route::group(['middleware' => ['web']], function () {
        //路由放在这里
    });
    
    routes.php

    reply
    0
  • Cancelreply