dousuize3082 2017-06-01 10:22
浏览 24
已采纳

注册表单验证问题

I'm adding a validation to my sign up form , the validate code is working but the errors don't shows up in the page

PHP code

 public function postSignUp(Request $request)
{
        $this->validate($request, [
            'email'=> 'required|email|unique:users',
            'first_name'=> 'required|max:120',
            'password' => 'required|min:4'
            ]);

        $email = $request['email'];
        $first_name = $request['first_name'];
        $password = bcrypt($request['password']);

        $user =  new User();

        $user->email = $email;
        $user->first_name = $first_name;
        $user->password = $password;

        $user->save();

        Auth::Login($user);

        return redirect()->route('dashboard');
}

Welcome.blade.php code

@section('content')
@if(count($errors) > 0)
<div class="row">
    <div class="col-md-6">
        <ul>
            @foreach($errors->all() as $error)
                <li>{{$error}}</li>
                @endforeach
        </ul>
    </div>
</div>
@endif

the php code is working because if i tried to register with an email that already taken it wont register but the error is that errors are not showing up in the welcome page

  • 写回答

2条回答 默认 最新

  • dongre8505 2017-06-01 10:41
    关注

    You are not passing the error messages back to the view. As stated at documentation

        if ($validator->fails())
        {
            return redirect('dashboard')->withErrors($validator);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题