php 找不到类“App\Validator”laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33116086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:23:05  来源:igfitidea点击:

Class 'App\Validator' not found laravel

phplaravelauthentication

提问by Nixxx27

please help im getting this error when creating an login and registration page in laravel 5.1

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

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

here is my AuthController.php

这是我的 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']),
        ]);
    }
}

and my register view

和我的注册视图

<!-- 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>

all of the codes are from laravel documention. that's why i dont know why it fails. please check where i get the error. thank you

所有代码都来自laravel文档。这就是为什么我不知道它为什么会失败。请检查我在哪里得到错误。谢谢你

also this is my routes controller

这也是我的路由控制器

// 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. my app is under the domain of http://localhost:8080/QADapps/auth/registeris there any issue because of that? i also move index.php and .htaccess from public into the root directory

PS 我的应用程序在http://localhost:8080/QADapps/auth/register的域下, 因此有什么问题吗?我还将 index.php 和 .htaccess 从 public 移动到根目录

回答by delatbabel

You actually need either this:

你实际上需要的是:

use Validator;

or this:

或这个:

use Illuminate\Support\Facades\Validator;

Illuminate\Validation\Validator is the underlying class containing the functionality but to use the static methods you need to pull in the facade class.

Illuminate\Validation\Validator 是包含功能的底层类,但要使用静态方法,您需要引入外观类。

The facade class Illuminate\Support\Facades\Validator is aliased to Validator in config/app.php

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

回答by user8583848

May be late here but might help someone later, this is what save use Illuminate\Validation\Rule;

在这里可能会迟到但可能会在以后帮助某人,这就是保存 use Illuminate\Validation\Rule;

回答by Adnan haider

use Illuminate\Support\Facades\Input;

use Illuminate\Support\Facades\Redirect;

使用 Illuminate\Support\Facades\Input;

使用 Illuminate\Support\Facades\Redirect;

and

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

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

Detail Solution:

详细解决方案: