3
我有两种型号,Threads
和Leads
。Laravel - 将相关型号返回至json
我试图用线程作为JSON对象返回主角,但我得到的是一个leads
为空的字段。
线程Model;
public function leads()
{
return $this->belongsTo('Leads');
}
潜在模型;
public function threads()
{
return $this->hasMany('Threads');
}
ThreadsController;
public function getLead($id=null)
{
$thread = Threads::thread($id)->with('leads')->get();
return Response::json($thread)->setCallback(Input::get('callback'));
}