Php 提交表单并在Laravel中将内容类型设置为application/json
我有以下表格:Php 提交表单并在Laravel中将内容类型设置为application/json,php,laravel,laravel-5,Php,Laravel,Laravel 5,我有以下表格: <form action="/create" method="post" enctype="application/json"> <input name="some_input" value="true"> <input name="user.name" value="John"> <input name="user.email" value="john@abc.com"> <button>Save</b
<form action="/create" method="post" enctype="application/json">
<input name="some_input" value="true">
<input name="user.name" value="John">
<input name="user.email" value="john@abc.com">
<button>Save</button>
</form>
我的怀疑是,我没有将内容类型设置为application/json
,但在这种情况下,我很难找到如何正确操作的信息
谢谢你的帮助 它的PHP行为是将
转换为.
(如果post/get请求中存在的话)
注:
变量名中的点和空格转换为下划线。对于
示例
变成$\u请求[“a\u b”]
模板中
<input name="user.email" value="john@abc.com">
要将其作为数组进行测试,请使用
<input name="user[name]" value="John">
<input name="user[email]" value="john@abc.com">
打印所有输入的可能副本,并检查您收到的内容
$request->all()
request()->input('user_name') // Will give you john@abc.com
<input name="user[name]" value="John">
<input name="user[email]" value="john@abc.com">
request()->input('user.name') // will give John
request()->input('user.email') // will give john@abc.com