我试图弄清楚如何将 $residence 之类的查询结果放入数据数组中。因为我这样做会给我错误数组到字符串的转换。有没有办法将查询结果转换为普通字符串?
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function insert(Request $request)
{
$id = auth()->user()->id;
$title = $request->input('title');
$clientid = $request->input('client');
$startdate = $request->input('startdate');
$enddate = $request->input('enddate');
$starttime = $request->input('starttime');
$endtime = $request->input('endtime');
$description = $request->input('description');
$firstname = DB::select('select firstname from clients where id='.$clientid);
$lastname = DB::select('select lastname from clients where id='.$clientid);
$housing = DB::select('select housing from clients where id='.$clientid);
$housenr = DB::select('select housenr from clients where id='.$clientid);
$residence = DB::select('select residence from clients where id='.$clientid);
$residencestring = json_encode($residence);
$data=array(
"uuid"=>$id,
"title"=>$title,
"residence"=>$residencestring,
"startdate"=>$startdate,
"enddate"=>$enddate,
"starttime"=>$starttime,
"endtime"=>$endtime,
"description"=>$description,
"firstname"=>$firstname,
"lastname"=>$lastname,
"housing"=>$housing,
"housenr"=>$housenr
);
//dd($data);
DB::table('tasks')->insert($data);
return redirect('/todo');
}