I am using Laravel 5.3 and I have 2 tables. Stations and Buses.
station table:
--------------
|id | Name |
--------------
Buses Table:
--------------------------------
|id | src_stn_id | dest_stn_id |
--------------------------------
src_stn_id and dest_stn_id are reference to the id column of station table.
I am using Eloquent and I am defining foreign key relations. Now the problem is that, I am defining relation like this in Bus model:
public function busStation()
{
return $this->belongsTo(\App\Models\BusStation::class, 'src_stn_id');
}
It is defined for src_stn_id but I don't know how to define for the dest_stn_id as they are referring to the same table. It will be great if someone can help me how to solve this problem.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire