RegistersUsers.php中的FatalErrorException第32行:在非对象上调用成员函数failed()在Laravel 5中
请帮助解决这个问题我很感谢谁能解决这个错误。 RegistersUsers.php中的代码是
<?php
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
trait RegistersUsers
{
use RedirectsUsers;
/**
* Show the application registration form.
*
* @return \Illuminate\Http\Response
*/
public function getRegister()
{
return view('auth.register');
}
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postRegister(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
Auth::login($this->create($request->all()));
return redirect($this->redirectPath());
}
}
控制器代码和控制器名称为AuthController.php
<?php namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
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;
public function validator(array $data){}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \Illuminate\Contracts\Auth\Authenticatable
*/
public function create(array $data){}
}
答案 0 :(得分:0)
在终端
中使用此命令创建请求php artisan make:request Name_of_request
在请求文件中,在rules()方法下创建规则。例如
public function rules()
{
return [
'title' => 'required|min:3',
'body' => 'required',
'tag_list' => 'required',
'image' => 'required|mimes:jpeg,jpg,png,gif'
];
}
创建规则后,在Controller上添加类,如下所示。
public function store(ArticleRequest $request){
//Your codes
}
ArticleRequest是请求类,$ request是post对象。
答案 1 :(得分:0)
在您的Auth Controller中需要包含'use Validator;'。
您的验证和创建方法也是空的。这些方法看起来像这样:
public function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:8',
]);
}
public function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}