laravel-ErrorException数组到字符串的转换

我试图弄清楚如何将查询结果如$ 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');
}
评论