-1
私は、次の表を持っている:Laravelショーデータ3テーブル
flights(id, title, number)
stations(id, title)
flight_price(id, price, flight_id, stationA_id, stationB_id)
flight_station(flight_id, station_id)
flight_station
は、ピボットテーブルです。
マイモデル:
class Flight extends Model
{
public function stations()
{
return $this->belongsToMany('App\Model\Station', 'flight_station', 'flight_id', 'station_id')
}
// To attach data
public function prices()
{
return $this->belongsToMany('App\Model\FlightPrice', 'flight_price', 'flight_id', 'stationA_id')
->withPivot('price');
}
public function price()
{
return $this->hasMany('App\Model\FlightPrice', 'flight_id');
}
}
// Station
class Station extends Model
{
public function flights()
{
return $this->belongsToMany('App\Model\Flight', 'flight_station', 'station_id', 'flight_id');
}
}
class FlightPrice extends Model
{
protected $table = 'flight_price';
public function flights()
{
return $this->belongsToMany('App\Model\Flight', 'flight_price');
}
}
私は次の結果(ID便で見つける。)必要があります。
|stationA_id|stationA_title||stationB_id|stationB_title|price|
。予想される結果をより正確に記述してください。これまで行ってきた仕事のいくつかを提供できますか? – louisfischer
データを取得して表示する方法。すべての雄弁な関係をリンクするには? –
ララカストのララベルで始まる本当に良いビデオがあります(https://laracasts.com/series/laravel-from-scratch-2017) – louisfischer