正确验证电子邮件,与此相关,我可以输入任何字符串

时间:2019-07-03 22:05:34

标签: laravel-5.8

我的个人产品有问题,这是我的第一个产品,当我在我的视图中传递电子邮件时,它接受任何字符串,例如hola @ hola或holahola.com,并且不会向我发送错误消息,解决它的不正确,请帮助。

我的控制器

public function create(Request $request) {

    $this->validate($request,[
      'name' => 'required|string|max:255',
      'email' => 'required|email|max:255|unique:users',
      'password' => 'required|string|min:8',
    ]);

    User::create([
      'name' => $request->name,
      'email' => $request->email,
      'password' => Hash::make($request->password),
  ]);
    return redirect('/properties')->with('success', 'User created');
}


public function update(Request $request)
{

    // this is not working
  $this->validate($request,[
    'name' => 'sometimes|required|string|max:255',
    'email' => 'sometimes|required|email|max:255',
    // 'email' => 'required|email|max:255|unique:users',
    'password' => 'required|string|min:8'
  ]);

  // updating a user
  $user = User::find(Auth::user()->id);

  $user->name = $request->input('name');
  $user->email = $request->input('email');

  if (
    $request->has('newpassword') &&
    $request->has('password_confirmation') &&
    $request->password_confirmation == $request->newpassword &&
    Hash::check($request->password,$user->password)
  ) {
    $user->password = Hash::make($request->newpassword);
    $user->save();
    return redirect('/properties')->with('success', 'User Updated');
  } else {
    return redirect('/properties')->with('error', 'Your current password does not match.');
  }

}

我的观点

            <div class="form-group row">
              <div class="col-md-4 col-form-label text-md-right">
                {{Form::label('title', 'User Email')}}
              </div>
              <div class="col-md-6">

{{Form :: text('email',$ user-> email,['type'=>'email','class'=>'form-control']}}}                                    

0 个答案:

没有答案