【发布时间】:2020-11-20 07:43:18
【问题描述】:
我想同时使用 join 和 first() 从两个表中选择信息,但我收到一条错误消息:
TypeError: Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of
the type string or null, object given,
这就是我正在做的事情:
public function getResult(Request $req){
$result= DB::table('form')
->select('form.*', 'test.*')
->join('test','test.form_id' , '=', 'form.id' )
->where('test.id',$req->id)
->first();
return $result;
}
注意:当我使用 get() 时它可以工作,但我只需要第一个选择的
你能告诉我该怎么做吗?
【问题讨论】:
-
会使用限制并获得工作吗?
->limit(1)->get()而不是->first() -
limit(1) 让我得到类似 [{......}] 的结果,但我想要类似 {........} 的结果