2017-07-07 63 views
1

我的網站得到了這樣的錯誤:會話存儲在Laravel沒有設置要求5.3

enter image description here

我也試過在中間件的網絡狀包裝路線一些解決它,它不工作

這裏是我的Kernel.php

<?php 

namespace App\Http; 

use App\Http\Middleware\Activated; 
use Illuminate\Foundation\Http\Kernel as HttpKernel; 

class Kernel extends HttpKernel 
{ 

    protected $middleware = [ 
     \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, 
    ]; 

    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, 
      \Illuminate\Routing\Middleware\SubstituteBindings::class, 
      \anlutro\LaravelSettings\SaveMiddleware::class, 
      \Barryvdh\Cors\HandleCors::class, 
      Activated::class 
     ], 

     'api' => [ 
      'throttle:60,1', 
      'bindings', 
     ], 
    ]; 
(The rest of file) 
    } 

我怎樣才能解決:((

+2

的可能的複製[Laravel - 對請求未設置會話存儲器(https://stackoverflow.com/questions/34449770/laravel-session-store-not-set-on-request) –

回答

2

如果您需要會話狀態,CSRF保護等,則需要使用Web中間件。

Route::group(['middleware' => ['web']], function() { 
    // your routes here 
}); 

您kernel.php應該是這樣的

protected $middleware = [ 
     \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, 
     \Illuminate\Session\Middleware\StartSession::class, 
    ]; 

    protected $middlewareGroups = [ 
     'web' => [ 
      \App\Http\Middleware\EncryptCookies::class, 
      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 

      \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
      \App\Http\Middleware\VerifyCsrfToken::class, 
      \Illuminate\Routing\Middleware\SubstituteBindings::class, 
      \anlutro\LaravelSettings\SaveMiddleware::class, 
      \Barryvdh\Cors\HandleCors::class, 
      Activated::class 
     ], 
+0

我也嘗試這但它沒有工作 –

+0

同樣的事情:((我也運行php工匠選擇清除緩存 –

+1

嘗試運行作曲家dump-autoload然後檢查 – Exprator

0

嗨,你需要創建一箇中間件

php artisan make:middleware AnyNameYouWant 

它會創建一個很好的樣板給你。

public function handle($request, Closure $next) 
{ 
    // Your Logic 
} 

    return redirect('whereever you want to redirect'); 
} 

然後將其包含在中間件

'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, 
     \Illuminate\Routing\Middleware\SubstituteBindings::class, 
     \anlutro\LaravelSettings\SaveMiddleware::class, 
     \Barryvdh\Cors\HandleCors::class, 
     \App\Http\Middleware\YourMiddleware::class 
    ],  

我希望這有助於

0

如果添加網絡中間件裏面你路線以任何理由不工作,然後嘗試添加這個以$中間件分成Kernel.php

protected $middleware = [ 
    //... 
    \Illuminate\Session\Middleware\StartSession::class, 
    \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
];