feat: add FlightImage model and update Flight image relation
This commit is contained in:
@@ -156,5 +156,16 @@ class Flight extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Favorite::class);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Reliese Model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FlightImage
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property int $flight_id
|
||||||
|
* @property int $file_id
|
||||||
|
* @property int|null $sort_order
|
||||||
|
* @property bool|null $is_default
|
||||||
|
* @property Carbon|null $created_at
|
||||||
|
* @property Carbon|null $updated_at
|
||||||
|
*
|
||||||
|
* @package App\Models
|
||||||
|
*/
|
||||||
|
class FlightImage extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'flight_images';
|
||||||
|
public static $snakeAttributes = false;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'flight_id' => '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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user