简体   繁体   English

如何将表单数据传递给 controller

[英]how to pass form data to controller

I am not getting how to pass data to the controller to update data, below I have given code.我不知道如何将数据传递给 controller 以更新数据,下面我给出了代码。

// below is my jquery which I am using to pass form data to the controller. // 下面是我的 jquery,我用它来将表单数据传递给 controller。

       function editProfile(profileData){     
                $("#profile_name").val(profileData.name) 
                $("#profile_id").val(profileData.id);   
                $("#profile-modal-lg").modal('show');
                $("#profile-form").attr('action',"text/edit/"+profileData.id);
                   }

// below is my route // 下面是我的路线

           Route::post('text/edit/{profile}', 'profileController@editProfileData')->name('profile.edit');

// inside controller I am having a function called edit profile // 在 controller 我有一个 function 称为编辑配置文件

        public function editProfileData(Profile $profile,profileRequest $request){
                        $profile->update($request->all());
                        return redirect()->back();
                    } 

Is your form method set to 'POST'?您的表单方法是否设置为“POST”? If not, try setting the form method attribute to 'POST'.如果没有,请尝试将表单方法属性设置为“POST”。 You might also want to add slash at the start of your url to target the absolute url.您可能还想在 url 的开头添加斜杠以定位绝对 url。

$("#profile-form")
  .attr('method', 'POST')
  .attr('action', `/text/edit/${profileData.id}`);

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

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