chore: finalize project updates

This commit is contained in:
2026-08-22 11:42:16 +03:30
parent 7719d750e9
commit 691290c340
55 changed files with 1923 additions and 6498 deletions
-93
View File
@@ -86,96 +86,3 @@ class Admin extends Authenticatable
return $this->status == 1;
}
}
//
///**
// * Created by Reliese Model.
// */
//
//namespace App\Models;
//
//use App\Enums\AdminStatus;
//use Carbon\Carbon;
//use Illuminate\Auth\Middleware\Authenticate;
//use Illuminate\Database\Eloquent\Factories\HasFactory;
//use Illuminate\Database\Eloquent\Model;
//
////use Illuminate\Foundation\Auth\Admin as User;
////use Illuminate\Foundation\Auth\Admin as Authenticate;
//
//
///**
// * Class Admin
// *
// * @property int $id
// * @property string $full_name
// * @property string $username
// * @property string $email
// * @property string $mobile
// * @property string $password
// * @property int $status
// * @property Carbon $created_at
// * @property Carbon $updated_at
// *
// * @package App\Models
// */
//class Admin extends Authenticate
//{
// protected $table = 'admins';
//
// public static $snakeAttributes = false;
//
// protected $casts = [
// 'status' => 'int',
// ];
//
// protected $hidden = [
// 'password',
// ];
//
// protected $fillable = [
// 'full_name',
// 'username',
// 'email',
// 'mobile',
// 'password',
// 'status',
// ];
//
// public function permissions()
// {
// return $this->belongsToMany(
// Permission::class,
// 'admin_permission',
// 'admin_id',
// 'permission_id'
// );
// }
//
//
// /**
// * بررسی دسترسی مدیر به ماژول مدیریت کاربران
// *
// * @param string $action view|edit|delete|password
// */
// public function canManageUsers(string $action): bool
// {
// // مدیریت کاربران فقط برای مدیر فعال مجاز است
// return $this->status == 1;
// }
//
//
// public function canManageTravelTypes(string $action): bool
// {
// return $this->status == 1;
// }
//
// public function canManageFlights(string $action): bool
// {
// return $this->status == 1;
// }
//
// public function canManageTours(string $action): bool
// {
// return $this->status == 1;
// }
//}
+1 -11
View File
@@ -53,19 +53,9 @@ class Comment extends Model
return $this->belongsTo(User::class);
}
// ✅ رابطه پلیمورفیک: نظر میتونه متعلق به محصول، خبر، پست و... باشه
// رابطه پلیمورفیک
public function commentable(): MorphTo
{
return $this->morphTo();
}
// public function comment()
// {
// return $this->belongsTo(Comment::class, 'commentable_id');
// }
//
// public function comments()
// {
// return $this->hasMany(Comment::class, 'commentable_id');
// }
}
+1 -1
View File
@@ -47,7 +47,7 @@ class Favorite extends Model
return $this->belongsTo(User::class);
}
// رابطه پلیمورفیک: علاقهمندی میتونه به محصول، خبر، پست و... وصل باشه
// رابطه پلیمورفیک
public function favoritable(): MorphTo
{
return $this->morphTo();
+54 -36
View File
@@ -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;
}
});
}