dongqian3750
2018-08-19 11:39
浏览 159
已采纳

如何使用没有标准auth的laravel RegisterController(php artisan make:Auth)

I thought that if($this->validator($request->all())) this would return true or false, but it returns a object every time returns true

use RegistersUsers;

protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware('guest');
    }


    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|string|max:255',
            'surname' => 'required|string|max:255',
            'age' => 'required|integer|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
        ]);
    }


    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'surname' => $data['surname'],
            'age' => $data['age'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

    public function register(Request $request){

        if($this->validator($request->all())){
            //create user
            // function after registration
            var_dump('success');
        }else{
            //redirect to ...
            var_dump('fail');
        }
    }

图片转代码服务由CSDN问答提供 功能建议

我认为 if($ this-> validator($ request-> all()) )这将返回true或false,但每次返回true时返回一个对象

 使用RegistersUsers; 
 
protected $ redirectTo ='/ home';  
 
公共函数__construct()
 {
 $ this-> middleware('guest'); 
} 
 
 
 protected function validator(array $ data)
 {
返回Validator  :: make($ data,[
'name'=>'required | string | max:255',
'surname'=>'required | string | max:255',
'age'=  >'required | integer | max:255',
'email'=>'required | string | email | max:255 | unique:users',
'password'=>'required | string | min  :6 |确认',
]); 
} 
 
 
受保护的函数create(array $ data)
 {
 return User :: create([
'name'=> $ data  ['name'],
'surname'=> $ data ['surname'],
'age'=> $ data ['age'],\  n'电子邮件'=>  $ data ['email'],
'密码'=>  bcrypt($ data ['password']),
]); 
} 
 
公共函数寄存器(Request $ request){
 
 if($ this-> validator($ request->  all())){
 //在注册后创建用户
 //函数
 var_dump('success'); 
} else {
 //重定向到... 
 var_dump('fail')  ; 
} 
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题