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'));
}