du kan også bruge den veltalende model til at definere forholdet.
For flere detaljer besøg også https://laravel.com/docs/5.3/eloquent-relationships
kasse to model -- 1. er "Flyv"
<?php
class Flights extends Model
{
protected $table = 'flights';
/**
* Get the From City detail.
*/
public function fromCity()
{
return $this->hasOne('App\Models\City', 'Pana', 'from_city');
}
/**
* Get the To city state.
*/
public function toCity()
{
return $this->hasOne('App\Models\City', 'Pana', 'to_city');
}
}
2. model er "By"
<?php
class City extends Model
{
protected $table = 'city';
}
Nu til hentning
Flights::where(id, $id)->with('toCity', 'fromCity')->get();