chore: finalize project updates
This commit is contained in:
+54
-36
@@ -36,45 +36,45 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class Tour extends Model
|
||||
{
|
||||
protected $table = 'tours';
|
||||
public static $snakeAttributes = false;
|
||||
protected $table = 'tours';
|
||||
public static $snakeAttributes = false;
|
||||
|
||||
protected $casts = [
|
||||
'travel_type_id' => 'int',
|
||||
'start_date' => 'datetime',
|
||||
'end_date' => 'datetime',
|
||||
'price' => 'float',
|
||||
'capacity' => 'int',
|
||||
'views_count' => 'int',
|
||||
'status' => 'int'
|
||||
];
|
||||
protected $casts = [
|
||||
'travel_type_id' => 'int',
|
||||
'start_date' => 'datetime',
|
||||
'end_date' => 'datetime',
|
||||
'price' => 'float',
|
||||
'capacity' => 'int',
|
||||
'views_count' => 'int',
|
||||
'status' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'travel_type_id',
|
||||
'title',
|
||||
'slug',
|
||||
'image',
|
||||
'description',
|
||||
'duration',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'price',
|
||||
'capacity',
|
||||
'views_count',
|
||||
'status'
|
||||
];
|
||||
protected $fillable = [
|
||||
'travel_type_id',
|
||||
'title',
|
||||
'slug',
|
||||
'image',
|
||||
'description',
|
||||
'duration',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'price',
|
||||
'capacity',
|
||||
'views_count',
|
||||
'status'
|
||||
];
|
||||
|
||||
public function travelType()
|
||||
{
|
||||
return $this->belongsTo(TravelType::class);
|
||||
}
|
||||
public function travelType()
|
||||
{
|
||||
return $this->belongsTo(TravelType::class);
|
||||
}
|
||||
|
||||
public function flights()
|
||||
{
|
||||
return $this->belongsToMany(Flight::class, 'tour_flights')
|
||||
->withPivot('id')
|
||||
->withTimestamps();
|
||||
}
|
||||
public function flights()
|
||||
{
|
||||
return $this->belongsToMany(Flight::class, 'tour_flights')
|
||||
->withPivot('id')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
// در فایل App\Models\Tour.php و App\Models\Flight.php
|
||||
|
||||
@@ -83,6 +83,23 @@ class Tour extends Model
|
||||
return $this->morphMany(Comment::class, 'commentable');
|
||||
}
|
||||
|
||||
public function favorites()
|
||||
{
|
||||
return $this->morphMany(\App\Models\Favorite::class, 'favoritable');
|
||||
}
|
||||
|
||||
|
||||
public function isFavoritedBy($user)
|
||||
{
|
||||
if (!$user) return false;
|
||||
|
||||
// استفاده از فیلدهای پلیمورفیک به جای tour_id
|
||||
return $this->favorites()
|
||||
->where('user_id', $user->id)
|
||||
->where('favoritable_id', $this->id)
|
||||
->where('favoritable_type', Tour::class)
|
||||
->exists();
|
||||
}
|
||||
|
||||
|
||||
protected static function booted()
|
||||
@@ -93,7 +110,8 @@ class Tour extends Model
|
||||
$tour->views_count = 0;
|
||||
}
|
||||
if (is_null($tour->status)) {
|
||||
$tour->status = 0; // فرض بر اینکه 0 یعنی غیرفعال/پیشنویس
|
||||
// فرض بر اینکه 0 یعنی غیرفعال یا پیشنویس
|
||||
$tour->status = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user