Laravel-未根据要求设置会话存储

我最近创建了一个新的Laravel项目,并遵循有关身份验证的指南。当我访问登录或注册路线时,出现以下错误:


ErrorException in Request.php line 775:

Session store not set on request. (View: C:\Users\Matthew\Documents\test\resources\views\auth\register.blade.php)

我还没有编辑任何核心Laravel文件,我只创建了视图并将路由添加到了route.php文件中


// Authentication routes

Route::get('auth/login', ['uses' => 'Auth\AuthController@getLogin', 'as' => 'login']);

Route::post('auth/login', ['uses' => 'Auth\AuthController@postLogin', 'as' => 'login']);

Route::get('auth/logout', ['uses' => 'Auth\AuthController@getLogout', 'as' => 'logout']);


// Registration routes

Route::get('auth/register', ['uses' => 'Auth\AuthController@getRegister', 'as' => 'register']);

Route::post('auth/register', ['uses' => 'Auth\AuthController@postRegister', 'as' => 'login']);

我在Laravel上没有太多经验,所以请原谅我的无知。我知道还有另一个问题要问同样的事情,但似乎没有一个答案对我有用。谢谢阅读!


编辑:


这是我所要求的register.blade.php。


@extends('partials.main')


@section('title', 'Test | Register')


@section('content')

    <form method="POST" action="/auth/register">

        {!! csrf_field() !!}

        <div class="ui input">

          <input type="text" name="name" value="{{ old('name') }}" placeholder="Username">

        </div>

        <div class="ui input">

          <input type="email" name="email" value="{{ old('email') }}" placeholder="Email">

        </div>

        <div class="ui input">

          <input type="password" name="password" placeholder="Password">

        </div>

        <div class="ui input">

          <input type="password" name="password_confirmation"placeholder="Confirm Password">

        </div>

        <div>

            <button class="ui primary button" type="submit">Register</button>

        </div>

    </form>

@endsection


牧羊人nacy
浏览 408回答 3
3回答

函数式编程

如果您需要会话状态,CSRF保护等等,则需要使用Web中间件。Route::group(['middleware' => ['web']], function () {&nbsp; &nbsp; // your routes here});

蝴蝶刀刀

就我而言(使用Laravel 5.3),仅添加以下2个中间件使我能够访问API路由中的会话数据:\App\Http\Middleware\EncryptCookies::class\Illuminate\Session\Middleware\StartSession::class整个声明($middlewareGroups在Kernel.php中):'api' => [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \App\Http\Middleware\EncryptCookies::class,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \Illuminate\Session\Middleware\StartSession::class,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'throttle:60,1',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'bindings',&nbsp; &nbsp; &nbsp; &nbsp; ],
打开App,查看更多内容
随时随地看视频慕课网APP