这是我的示例代码,您可以尝试一下,希望对您有所帮助
/*---------------------------------------------------------
* Relationship with same table, means recursive key
* --------------------------------------------------------
*/
//this will get the childern against parent.
public function doseage_childs(){
return $this->hasMany('App\Models\DoseageForm', 'parent_id', 'id');
}
//this will get the parent against childern
public function doseage_parent(){
return $this->belongsTo('App\Models\DoseageForm', 'parent_id', 'id');
}
Edited
更新你的这个方法
public function TicketReplies() {
return $this->belongsTo('\App\Models\TicketModel', 'TicketID');
}
像这样
public function TicketReplies() {
return $this->hasMany('\App\Models\TicketModel','ParentTicketID' ,'TicketID');
}
并像这样更新你的查询模型,因为你已经得到了TicketReplies
关系。
$Ticket = \App\Models\TicketModel
::with('TicketReplies')
->where('TicketID', '=', $TicketID)
->first();
那么你们的关系就会发挥作用