我正在使用API我有一个资源控制器来CRUD驱动程序,在我的更新功能中我收到此错误
for node in tree.findall('.//name'):
mylist = list(node.text)
print mylist
#output--
['M','e','d', 'i','a','n',' ','C','o','n','d','o',' ','V','a','l','u', 'e']
['M','e','d','i','a','n',' ','H','o','m','e',' ','V','a','l','u','e']
['H', 'o', 'm', 'e', ' ', 'T', 'y', 'p', 'e']
我在我的更新方法中def joinlists(lists):
results = []
for list1 in lists:
results.append(''.join(lists))
return results
print joinlists(makelist)
获得了所有JSON响应
mylist2 = ['Median Condo Value', 'Median Home Value, 'Home Type']
但是QueryException in Connection.php line 770:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'registration_center' cannot be null (SQL: update `drivers` set `registration_center` = , `registration_date` = 04-02-2017, `sponsor_name` = , `event_name` = , `registration_id` = 040217001, `profile_photo` = , `first_name` = , `last_name` = ,`updated_at` = 2017-02-04 04:54:54 where `id` = 3)
我得到了dd($request);
我的方法
Request {#40
#json: ParameterBag {#32
#parameters: array:1 [
"data" => array:61 [
"id" => 3
"agent_id" => "201705"
"registration_center" => "dfgsdfgdfgdsdfgdf"
"registration_date" => "03-02-2017"
"sponsor_name" => "Sponser Name"
"event_name" => "RC"
"registration_id" => "FRTGHY030217001"
"profile_photo" => ""","
"first_name" => "Walter"
"last_name" => "White"
"created_at" => "2017-01-24 10:08:42"
"updated_at" => "2017-02-03 11:33:52"
"deleted_at" => null
]
]
}
我的路线是
dd($request->registration_center);
期待急需的帮助
谢谢
答案 0 :(得分:2)
从Laravel请求访问POSTed数据的一般方法是使用input
方法。
$field = $request->input('field');
查看您的示例,似乎Request
对象中有一个data
字段,它是一个关联数组,registration_center
就在其中。如果我做对了,那么在你的情况下,你会使用:
$update_driver->registration_center = $request->input('data')['registration_center'];
// or, using Laravel's "dot"-syntax
$update_driver->registration_center = $request->input('data.registration_center');
访问数据。对于您尝试检索的所有其他值也是如此。
答案 1 :(得分:1)
由于它是一个数组,您需要使用以下命令访问它:
$request['data']['registration_center'];