简体   繁体   English

Laravel 请求始终返回 null

[英]Laravel request always return null

So i have this view所以我有这个观点

<form method="POST" action="/store">
<div class="control-group after-add-more">  
<div class="form-group">                                                                    
<label>Partner :</label>                                                                        
<input type="text" class="form-control" id="partner" name="partner" value="" placeholder="Partner Name" />                                                                  
</div>                                                          
<button class="btn btn-success add-more" type="button">                                                         
<i class="glyphicon glyphicon-plus"></i> Plus Partner</button>                                                      
                                            
<div class="copy hide">                                                         
<div class="control-group">                                                                     
<div class="form-group">                                                                        
<label> Partner :</label>                                                                       
<input type="text" class="form-control" id="partner2" name="partner2" value="" placeholder="Partner Name" />                                                                    
</div>                                                                                                                              
<button class="btn btn-danger remove" type="button">                                                                    
<i class="glyphicon glyphicon-remove"></i>                                                          
Delete Partner</button>
</div>      
                                            
</div>
<button type="submit">Submit</button>
</form>

this is jquery that i use这是我使用的 jquery

$(document).ready(function() {
         $(".add-more").click(function() {
            var html = $(".copy").html();
            $(".after-add-more").after(html);
        });
        $("body").on("click", ".remove",function() {
            $(this).parents(".control-group").remove();
        });
});

but when i try to submit, the input partner2 is returning null value但是当我尝试提交时,输入 partner2 返回 null 值

this is my controller这是我的 controller

$kerma = Kerma::find(1)->get();
$kerma->partner()->createMany(['partner' => $request->input('partner')],['partner' => $request->input('partner2')])

anyone have a solution for me?有人能给我解决方案吗? thanks in advance提前致谢

When submitting your request to the form:向表单提交请求时:

  1. The routes file should have the POST method configured.路由文件应该配置了POST方法。
Route::post('store', 'YourController@yourmethod');
  1. Addition of CSRF token to the Form to prevent Page Expired issue.将 CSRF 令牌添加到表单以防止Page Expired问题。 So, your blade file should be like below:因此,您的刀片文件应如下所示:
<form method="POST" action="{{url('store')}}">
@csrf
<div class="control-group after-add-more">  
<div class="form-group">                                                                    
<label>Partner :</label>                                                                        
<input type="text" class="form-control" id="partner" name="partner" value="" placeholder="Partner Name" />                                                                  
</div>                                                          
<button class="btn btn-success add-more" type="button">                                                         
<i class="glyphicon glyphicon-plus"></i> Plus Partner</button>                                                      
                                            
<div class="copy hide">                                                         
<div class="control-group">                                                                     
<div class="form-group">                                                                        
<label> Partner :</label>                                                                       
<input type="text" class="form-control" id="partner2" name="partner2" value="" placeholder="Partner Name" />                                                                    
</div>                                                                                                                              
<button class="btn btn-danger remove" type="button">                                                                    
<i class="glyphicon glyphicon-remove"></i>                                                          
Delete Partner</button>
</div>      
                                            
</div>
<button type="submit">Submit</button>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM