Php Laravel-5.5:未根据请求设置会话存储
我有一个简单的控制器: 代码输入框控制器: 如何在Laravel 5.5中根据请求设置会话以验证数据? 我必须验证Php Laravel-5.5:未根据请求设置会话存储,php,laravel,laravel-5.5,Php,Laravel,Laravel 5.5,我有一个简单的控制器: 代码输入框控制器: 如何在Laravel 5.5中根据请求设置会话以验证数据? 我必须验证composeroute中的数据 Routes Route::group(['prefix' => 'inbox', 'middleware' => 'auth'], function(){ Route::get('/', ['uses' => 'InboxController@index',])->name('inbox'); Route::
compose
route中的数据
Routes
Route::group(['prefix' => 'inbox', 'middleware' => 'auth'], function(){
Route::get('/', ['uses' => 'InboxController@index',])->name('inbox');
Route::match(['get', 'post'], '/message/{id?}', ['uses'=>'InboxController@message'])->name('message');
Route::match(['get', 'post'], '/compose', ['uses'=>'InboxController@compose'])->name('compose');
});
我的中间件组代码:
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
您需要添加
\Illuminate\Session\Middleware\StartSession::class
在kernal.php web组内部的中间件中。如果需要会话状态、CSRF保护等,则需要使用web中间件
Route::group(['middleware' => ['web']], function () {
// your routes here
});
发生这种情况是因为 在Kernal.php中(位置->/app/Http) 有两个阵列$middleware和$routemidleware 不要在$middleware数组中创建别名(命名)。它必须在$routeMiddleware数组中创建 比如说
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'checkLogin' => \App\Http\Middleware\CheckLogin::class,
//here you have to add your middleware naming not in the $middleware array
];
向我们展示您的内核中间件组您可以在更新的问题@Sohel0415change
返回视图('compose',compact('array'))中看到中间件组代码>而不是返回视图('compose',$array)
如果您没有将web
组分配给您的路由,则您没有会话我已经添加了此类,但我没有在路由中使用中间件['web']。您只使用中间件['auth']。错误在哪里?如何修复它@萨乌拉布·帕雷赫
Route::group(['middleware' => ['web']], function () {
// your routes here
});
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'checkLogin' => \App\Http\Middleware\CheckLogin::class,
//here you have to add your middleware naming not in the $middleware array
];