【发布时间】:2017-06-09 02:41:40
【问题描述】:
我有 2 个变量中的 2 个查询的结果,我有一个 JSON 对象我想将查询结果 append 到该 JSON,然后将其返回给用户
在可能的控制器中,我得到了所有的结果
if ($request->wantsJson()) {
$agent_id = $request->user()->id;
$drivers_cout = Driver::all()->count();
$drivers_cout_by_agent = Driver::where(['agent_id' => $agent_id])->get()->count();
return $request->user();
}
//the result of $request->user();
#attributes: array:12 [
"id" => 201702
"name" => "Agent"
"email" => "agent@gmail.com"
"phone_number" => "966355826"
]
//and i want something like
#attributes: array:12 [
"id" => 201702
"name" => "Agent"
"email" => "agent@gmail.com"
"phone_number" => "966355826"
"drivers_count" => "96" //How do i append these two
"drivers_cout_by_agent" => "16"
]
谢谢
【问题讨论】:
标签: php json laravel object laravel-5.3