请帮助我在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从公共目录移动到根目录
4条答案
按热度按时间ht4b089n1#
你实际上需要的是:
或者这个:
Illuminate\Validation\Validator是包含功能的底层类,但要使用静态方法,您需要拉入外观类。
facade类Illuminate\Support\Facades\Validator别名为config/app.php中的Validator
2w2cym1i2#
在这里可能会迟到,但可能会帮助别人以后,这是什么保存
use Illuminate\Validation\Rule;
2w2cym1i3#
使用Illuminate\Support\Facades\Input;
使用Illuminate\Support\Facades\Redirect;
和
$validator = \Validator::make(Input::all(),$rules);
Detail Solution:
dm7nw8vv4#
仅尝试
它会工作得很好!