问题描述
Users
此表中的某些字段默认为空.
Some fields in this table are null by default.
我需要更新这些字段并设置非空数据.
I need to update these fields and set not null data.
为此,我尝试在 Laravel 中使用 PATCH
方法:
For this I try to use PATCH
method in Laravel:
路由:
控制器:
这是否意味着我可以传递任何数据进行更新?我应该将 $id
参数相对传递给路由和控制器吗?
Does it mean that I can pass any data to update?
Should I pass $id
parameter to routing and controller relatively?
如何在 Laravel 中为 PATCH 方法使用正确的处理程序?
How to use right handler for PATCH method in Laravel?
推荐答案
你的路线是:
用以下用于所有 CRUD 操作的路由替换你的路由:
replace your route with following route that use for all CRUD opration:
如果您使用 ajax 提交数据,则将您的类型和网址替换为以下内容:
if you use ajax for submit data then replace your type and url with following:
如果您不使用 ajax,请使用以下内容:
if you don't use ajax than use following:
更新:在 5.6 版之后,您可以在任何刀片文件中对上述函数使用这些语法:
update: after version 5.6 you can use these syntax for above functions in any blade file:
这篇关于如何在 Laravel 中使用补丁请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!