feat: add tour enums, update Tour model, and create TourImage relation
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums\Admin\Tour;
|
||||||
|
|
||||||
|
enum TourMode:int
|
||||||
|
{
|
||||||
|
case AIR = 0;
|
||||||
|
case LAND = 1;
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::AIR => 'زمینی',
|
||||||
|
self::LAND => 'هوایی',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums\Admin\Tour;
|
||||||
|
|
||||||
|
enum TourScope:int
|
||||||
|
{
|
||||||
|
case DOMESTIC = 0;
|
||||||
|
case INTERNATIONAL = 1;
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::DOMESTIC => 'داخلی',
|
||||||
|
self::INTERNATIONAL => 'خارجی',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums\Admin\Tour;
|
||||||
|
|
||||||
|
enum TourType:int
|
||||||
|
{
|
||||||
|
case RECREATIONAL = 0;
|
||||||
|
case TOURISM = 1;
|
||||||
|
case PILGRIMAGE = 2;
|
||||||
|
case ECO_TOURISM = 3;
|
||||||
|
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::RECREATIONAL => 'تفریحی',
|
||||||
|
self::TOURISM => 'گردشگری',
|
||||||
|
self::PILGRIMAGE => 'زیارتی',
|
||||||
|
self::ECO_TOURISM => 'طبیعتگردی'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
-9
@@ -6,11 +6,15 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\Admin\Tour\TourMode;
|
||||||
|
use App\Enums\Admin\Tour\TourScope;
|
||||||
|
use App\Enums\Admin\Tour\TourType;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Tour
|
* Class Tour
|
||||||
@@ -34,6 +38,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
*/
|
*/
|
||||||
class Tour extends Model
|
class Tour extends Model
|
||||||
{
|
{
|
||||||
|
use SoftDeletes;
|
||||||
protected $table = 'tours';
|
protected $table = 'tours';
|
||||||
public static $snakeAttributes = false;
|
public static $snakeAttributes = false;
|
||||||
|
|
||||||
@@ -41,8 +46,9 @@ class Tour extends Model
|
|||||||
'origin_city_id' => 'int',
|
'origin_city_id' => 'int',
|
||||||
'destination_city_id' => 'int',
|
'destination_city_id' => 'int',
|
||||||
'file_id' => 'int',
|
'file_id' => 'int',
|
||||||
'tour_mode'=> 'int',
|
'tour_mode'=> TourMode::class,
|
||||||
'tour_scope' => 'int',
|
'tour_scope' => TourScope::class,
|
||||||
|
'tour_type' => TourType::class,
|
||||||
'views_count' => 'int'
|
'views_count' => 'int'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -61,18 +67,16 @@ class Tour extends Model
|
|||||||
#[Scope]
|
#[Scope]
|
||||||
protected function applySort(Builder $query, ?string $sort = null): void
|
protected function applySort(Builder $query, ?string $sort = null): void
|
||||||
{
|
{
|
||||||
|
$query->withMin('tourDepartures', 'price')
|
||||||
|
->withMax('tourDepartures', 'price');
|
||||||
|
|
||||||
switch ($sort) {
|
switch ($sort) {
|
||||||
|
|
||||||
case 'lowest':
|
case 'lowest':
|
||||||
$query->withMin('tourDepartures', 'price')
|
$query->orderBy('tour_departures_min_price');
|
||||||
->orderBy('tour_departures_min_price');
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'highest':
|
case 'highest':
|
||||||
$query->withMax('tourDepartures', 'price')
|
$query->orderByDesc('tour_departures_max_price');
|
||||||
->orderByDesc('tour_departures_max_price');
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$query->orderByDesc('id');
|
$query->orderByDesc('id');
|
||||||
break;
|
break;
|
||||||
@@ -106,4 +110,15 @@ class Tour extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Favorite::class);
|
return $this->hasMany(Favorite::class);
|
||||||
}
|
}
|
||||||
|
public function images()
|
||||||
|
{
|
||||||
|
return $this->hasMany(TourImage::class)
|
||||||
|
->orderBy('sort_order');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function coverImage()
|
||||||
|
{
|
||||||
|
return $this->hasOne(TourImage::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 TourImage
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property int $tour_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 TourImage extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'tour_images';
|
||||||
|
public static $snakeAttributes = false;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'tour_id' => 'int',
|
||||||
|
'file_id' => 'int',
|
||||||
|
'sort_order' => 'int',
|
||||||
|
'is_default' => 'bool'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'tour_id',
|
||||||
|
'file_id',
|
||||||
|
'sort_order',
|
||||||
|
'is_default'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function tour()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Tour::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function file()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(File::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user