gpt4 book ai didi

php - http中的嵌套参数是什么?

转载 作者:太空狗 更新时间:2023-10-29 13:30:27 26 4
gpt4 key购买 nike

Laravel Docs on validation他们谈到“嵌套参数”:

If your HTTP request contains "nested" parameters, you may specify them in your validation rules using "dot" syntax:

$this->validate($request, [
'title' => 'required|unique:posts|max:255',
'author.name' => 'required',
'author.description' => 'required',
]);

这个嵌套的 HTML 会是什么样子?我四处搜索,除了表单嵌套之外什么也没发现。另外,“点”语法,这是 Laravel 特有的吗?

最佳答案

点符号用于轻松访问数组元素,并使其选择器更加“流畅”。

正在验证 author.name相当于检查输入值 <input type="text" name="author[name]" /> .

这使得拥有多个模型表单或对相关数据进行分组变得更好 =)。然后,您可以通过执行 $request->request('author'); 之类的操作来获取该事物的所有数据。这将为您提供使用 author[*] 提交的所有值的集合/数组. Laravel 还将它与它的配置访问器一起使用 - 所以 config.setting.parameter相当于config[setting][parameter]

基本上可以更轻松地处理数组数据。

参见 https://github.com/glopezdetorre/dot-notation-access一些例子!

关于php - http中的嵌套参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38016938/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com