无法在Laravel 5中验证注册 [英] Signup is unable to validated in Laravel 5

查看:114
本文介绍了无法在Laravel 5中验证注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的问题是检查新用户输入的注册/注册详细信息是否已经存在于数据库中?如果已经存在,则消息应显示您已经注册,请登录.但没有成功.

I am facing the problem with checking whether the new user entering his details for registration/signup, is already exist in database or not? If already existing, message should display that you are already registered, please login. But not getting any success.

这是路线:

Route::get('/registration_page', 'makelogin@registration_function');

这是控制者:

public function registration_function(Request $request)
{
    $nam_value = $request->nam;
    $email_value = $request->r_email;
    $password_value = $request->r_password;
    $city_value = $request->city;

    $this->validate($request, [
        'email' => 'required|unique:registered|max:255',
        'password' => 'required',
    ]);

    $reg=DB::table('registered')->insert(['name' => $nam_value, 'email' => $email_value, 'password'=>$password_value,'city'=>$city_value]);
    return redirect('makelogin_page')->with('status','Registered Successfully');
}

这是blade.php页面:

<div class="container">
  <h3>New user ?</h3>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#registration">Register</button>
  <!-- Modal -->
  <div class="modal fade" id="registration" role="dialog">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Registration</h4>
        </div>
        <div class="modal-body">
          <p>Please Register Yourself Here</p>
          <form role="form" action="registration_page" method="get">
            <div class="form-group">
              <input type="text" class="form-control" name="nam" placeholder="Your Name Please" style="width:265px;">
            </div>
            <div class="form-group">
              <input type="email" class="form-control" name="r_email" placeholder="Your Email Please" style="width:265px;">
            </div>
            <div class="form-group">
              <input type="password" class="form-control" name="r_password" placeholder="Please enter a password" style="width:265px;">
            </div>
            <div class="form-group">
              <input type="text" class="form-control" name="city" placeholder="Please enter your city" style="width:265px;">
            </div>
            <div class="form-group">
              <input type="submit" class="btn btn-info" value="Register">
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>

推荐答案

在您的注册功能registration_function中进行

user App\User;
public function registration_function(Request $request)
{
  $user_db = User::all();
  $user_entered = $request->all();

  if(in_array($user_entered, $user_db)){
      Session::message("User already entered please login");
      return redirect()->route('login');
  }else{
      $this->validate($request, [
      'email' => 'required|unique:registered|max:255',
      'password' => 'required',
     ]);

    User::create($request);
  }

}

希望这会有所帮助.

这篇关于无法在Laravel 5中验证注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆