diff --git a/app/Models/Flight.php b/app/Models/Flight.php index f252605..797ca79 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -156,5 +156,16 @@ class Flight extends Model { return $this->hasMany(Favorite::class); } + public function images() + { + return $this->hasMany(FlightImage::class) + ->orderBy('sort_order'); + } + + public function coverImage() + { + return $this->hasOne(FlightImage::class) + ->where('is_default', true); + } } diff --git a/app/Models/FlightImage.php b/app/Models/FlightImage.php new file mode 100644 index 0000000..08e74ea --- /dev/null +++ b/app/Models/FlightImage.php @@ -0,0 +1,53 @@ + 'int', + 'file_id' => 'int', + 'sort_order' => 'int', + 'is_default' => 'bool' + ]; + + protected $fillable = [ + 'flight_id', + 'file_id', + 'sort_order', + 'is_default' + ]; + + public function flight() + { + return $this->belongsTo(Flight::class); + } + + public function file() + { + return $this->belongsTo(File::class); + } +}