Laravel 5.1 基本身份验证

Laravel 5.1 Basic Authentication

我是laravel新手,有几个疑惑请教。 这就像当我使用默认由 Laravel 5.1 提供的 Auth Class 进行基本登录和注册时,它给我 404 Not found 错误。

这是我的目录结构:

resources/views/auth/register.blade.php
resources/views/auth/login.blade.php

我正在关注 laravel 5.1 官方文档,以获取此信息。 当我在注册表单中按下提交按钮时,它会抛出 404 未找到错误。

register.blade.php

<!-- resources/views/auth/register.blade.php -->

<form method="POST" action="/auth/register">
    {!! csrf_field() !!}

    <div>
        Name
        <input type="text" name="name" value="{{ old('name') }}">
    </div>

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

    <div>
        Password
        <input type="password" name="password">
    </div>

    <div>
        Confirm Password
        <input type="password" name="password_confirmation">
    </div>

    <div>
        <button type="submit">Register</button>
    </div>
</form>

我有我的授权 class 作为 :

app/Http/Controllers/Auth/AuthController.php
app/Http/Controllers/Auth/PasswordController.php

我的基本路线:

// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');


Route::controllers([
   'password' => 'Auth\PasswordController',
]);

它仍然抛出 404 未找到错误。任何解决方案我缺少什么? 路由也显示 AuthController@getRegister,我是否必须手动创建 getRegister 的函数,因为我找不到。? 我是 laravel

的新手

我的AuthController.php也长得像

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;
    protected $redirectPath = '/dashboard';
    protected $loginPath = '/login';
    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

我不确定,但我想问题出在表单中的 action 属性上。切勿在 laravel 中的表单操作中使用纯 url。
尝试使用

<form method="POST" action="{{ url('/auth/login') }}">


您也可以通过这种方式创建表单:(您必须在 composer.json 中添加依赖项,在 google 中搜索关于 laravel 表单)

{!! Form::open(array('url' => 'http://other.domain.com')) !!}
  <input type="text" name="test" value="something" />
  <button type="submit">Submit</button>
{!! Form::close() !!}