类'App \ Validator'找不到laravel

时间:2015-10-14 03:22:00

标签: php laravel authentication

请在laravel 5.1中创建登录和注册页面时帮助我获取此错误

FatalErrorException in AuthController.php line 44:
Class 'App\Validator' not found

这是我的AuthController.php

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Validator;
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;

    /**
     * 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']),
        ]);
    }
}

和我的注册视图

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

<form method="POST" action="/QADapps/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>

所有代码均来自laravel文档。这就是为什么我不知道它失败的原因。请检查我收到错误的地方。谢谢

这也是我的路线控制器

// 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');

P.S。我的应用程序属于 http://localhost:8080/QADapps/auth/register  因为那有什么问题吗? 我还将index.php和.htaccess从public移动到根目录

3 个答案:

答案 0 :(得分:19)

你实际上需要这个:

use Validator;

或者这个:

use Illuminate\Support\Facades\Validator;

Illuminate \ Validation \ Validator是包含该功能的基础类,但是要使用拉入Facade类所需的静态方法。

Facade类Illuminate \ Support \ Facades \ Validator在config / app.php中为Validator别名

答案 1 :(得分:0)

可能在这里迟到,但可能稍后再帮助别人,这是保存 use Illuminate\Validation\Rule;

的方法

答案 2 :(得分:0)

  

使用Illuminate \ Support \ Facades \ Input;

     

使用Illuminate \ Support \ Facades \ Redirect;

  

$ validator = \ Validator :: make(输入:: all(),$ rules);

Detail Solution: