注册在 Laravel 5 中不起作用

Posted

技术标签:

【中文标题】注册在 Laravel 5 中不起作用【英文标题】:Registration not working in Laravel 5 【发布时间】:2016-12-19 03:02:31 【问题描述】:

我正在尝试对注册页面使用验证,但没有成功,只是显示相同的页面,并且没有数据被插入到数据库中,无论是在唯一的电子邮件中还是在重复的电子邮件中。我在 Laravel 5 中这样做。

如果我的路线在routes.php 文件中:

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>

【问题讨论】:

它是否显示任何错误?你已经导入了 Validator 和 validateRequest? 没有显示任何错误,只是重定向了与我在控制器中所做的相同的页面。 如何导入 Validator 和 validateRequest ? 为什么你又问了同样的问题? signup is unable to validated in laravel 5 laravel.com/docs/5.2/validation 看看这里 【参考方案1】:

我自己解决了我的问题

这是它的路线

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;
>       $hashed_password = bcrypt($password_value);
>       $valid_user = DB::table('registered')
>                         ->where('email',$email_value)
>                         ->get();
>       if($valid_user)
>       
>         return redirect('makelogin_page')->with('status_validate','You are already registered with us, Plaese login, Did you forgot your
> password ?');
>       
>       else
>       
>         $reg=DB::table('registered')->insert(['name' => $nam_value, 'email' => $email_value,
> 'password'=>$hashed_password,'city'=>$city_value]);
>         return redirect('makelogin_page')->with('status','Registered Successfully');
>       
>     

这是它的观点

> <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;" required/>
>               </div>
>               <div class="form-group">
>                 <input type="email" class="form-control" name="r_email" placeholder="Your Email Please" style="width:265px;"
> required/>
>               </div>
>               <div class="form-group">
>                 <input type="password" class="form-control" name="r_password" placeholder="Please enter a password"
> style="width:265px;" required/>
>               </div>
>               <div class="form-group">
>                 <input type="text" class="form-control" name="city" placeholder="Please enter your city" style="width:265px;" required/>
>               </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>   </div>

【讨论】:

【参考方案2】:

这是在 Laravel4 中,但它可能会有所帮助

http://cubettech.com/blog/how-to-create-user-registration-form-in-laravel/

【讨论】:

以上是关于注册在 Laravel 5 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章

postIndex() 在 Laravel 中不起作用

护照身份验证在 laravel 5.3 中不起作用

barryvdh/laravel-cors 配置在 Laravel 5.6 中不起作用;忽略'allowedMethods'

会话在中间件 Laravel 5 中不起作用

数据表在 Laravel 5.3 中不起作用

Route::currentRouteAction 在 laravel 5.4 中不起作用