diff --git a/ShopFlow/app/Filament/Resources/CategoryResource.php b/ShopFlow/app/Filament/Resources/CategoryResource.php index a4046585..a802f1cd 100644 --- a/ShopFlow/app/Filament/Resources/CategoryResource.php +++ b/ShopFlow/app/Filament/Resources/CategoryResource.php @@ -78,8 +78,8 @@ public static function table(Table $table): Table ->limit(60) ->searchable(), Tables\Columns\TextColumn::make('status') - ->getStateUsing(fn (Category $record): string => CategoryStatusEnum::from((int) $record->status)->label()) - ->color(fn (Category $record): string => CategoryStatusEnum::from((int) $record->status)->color()) + ->getStateUsing(fn (Category $record) => $record->status->label()) + ->color(fn (Category $record): string => $record->status->color()) ->sortable(), Tables\Columns\IconColumn::make('no_index') ->boolean(), diff --git a/ShopFlow/app/Filament/Resources/UserResource.php b/ShopFlow/app/Filament/Resources/UserResource.php index 52e52236..8f931552 100644 --- a/ShopFlow/app/Filament/Resources/UserResource.php +++ b/ShopFlow/app/Filament/Resources/UserResource.php @@ -151,8 +151,8 @@ public static function table(Table $table): Table ->sortable(), Tables\Columns\TextColumn::make('national_id') ->searchable(), Tables\Columns\TextColumn::make('status') - ->getStateUsing(fn (User $user) => UserStatusEnum::from($user->status)->label()) - ->color(fn (User $user) => UserStatusEnum::from($user->status)->color()) + ->getStateUsing(fn (User $user) => $user->status->label()) + ->color(fn (User $user) => $user->status->color()) ->badge(), Tables\Columns\TextColumn::make('created_at') ->dateTime() diff --git a/ShopFlow/app/Models/Category.php b/ShopFlow/app/Models/Category.php index 5ee5b163..b3a9aad7 100644 --- a/ShopFlow/app/Models/Category.php +++ b/ShopFlow/app/Models/Category.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Enums\CategoryStatusEnum; +use App\Enums\UserStatusEnum; use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; @@ -23,7 +24,7 @@ * @property string|null $canonical * @property positive-int|null $parent_id * @property positive-int|null $image_id - * @property bool $status + * @property CategoryStatusEnum $status * @property Collection $images * @property Carbon|null $created_at * @property Carbon|null $updated_at @@ -46,6 +47,11 @@ class Category extends Model 'status', ]; + protected $casts = [ + 'no_index' => 'boolean', + 'status' => CategoryStatusEnum::class, + ]; + public function images(): MorphMany { return $this->morphMany(Image::class, 'imageable'); diff --git a/ShopFlow/app/Models/User.php b/ShopFlow/app/Models/User.php index 5ad157cc..a6b4ce25 100644 --- a/ShopFlow/app/Models/User.php +++ b/ShopFlow/app/Models/User.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Enums\RolesEnum; +use App\Enums\UserStatusEnum; use Carbon\Carbon; use Filament\Models\Contracts\FilamentUser; use Filament\Models\Contracts\HasName; @@ -24,7 +25,7 @@ * @property Carbon $mobile_verified_at * @property string $national_id * @property string $login_token - * @property positive-int $status + * @property UserStatusEnum $status * @property Collection
$addresses * @property Carbon|null $email_verified_at * @property Carbon|null $login_token_expire_time @@ -74,6 +75,7 @@ protected function casts(): array return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', + 'status' => UserStatusEnum::class, ]; } diff --git a/ShopFlow/database/seeders/CategorySeeder.php b/ShopFlow/database/seeders/CategorySeeder.php index 1ef0aa98..598a66dd 100644 --- a/ShopFlow/database/seeders/CategorySeeder.php +++ b/ShopFlow/database/seeders/CategorySeeder.php @@ -4,7 +4,10 @@ namespace Database\Seeders; +use App\Enums\CategoryStatusEnum; +use App\Models\Category; use Illuminate\Database\Seeder; +use Illuminate\Support\Arr; // Import the Arr facade class CategorySeeder extends Seeder { @@ -13,6 +16,116 @@ class CategorySeeder extends Seeder */ public function run(): void { - // + $categories = [ + [ + 'id' => 1, + 'heading' => 'لوازم جانبی گوشی', + 'slug' => 'mobile-accessories', + 'content' => 'انواع لوازم جانبی گوشی موبایل.', + 'title' => 'لوازم جانبی گوشی', + 'description' => 'لوازم جانبی متنوع برای گوشی‌های موبایل.', + 'no_index' => false, + 'canonical' => null, + 'parent_id' => null, + 'status' => CategoryStatusEnum::ACTIVE, + 'children' => [ + [ + 'id' => 2, + 'heading' => 'قاب و کاور گوشی', + 'slug' => 'phone-cases', + 'content' => 'محافظ‌های متنوع برای گوشی‌های موبایل.', + 'title' => 'قاب و کاور گوشی', + 'description' => 'انواع قاب و کاور با طراحی‌های زیبا.', + 'no_index' => false, + 'canonical' => null, + 'parent_id' => 1, + 'status' => CategoryStatusEnum::ACTIVE, + ], + [ + 'id' => 3, + 'heading' => 'محافظ صفحه نمایش', + 'slug' => 'screen-protectors', + 'content' => 'محافظ صفحه‌های مختلف برای گوشی.', + 'title' => 'محافظ صفحه نمایش', + 'description' => 'محافظت از صفحه نمایش گوشی شما.', + 'no_index' => false, + 'canonical' => null, + 'parent_id' => 1, + 'status' => CategoryStatusEnum::ACTIVE, + ], + [ + 'id' => 4, + 'heading' => 'پاوربانک', + 'slug' => 'power-banks', + 'content' => 'انواع پاوربانک با ظرفیت‌های مختلف.', + 'title' => 'پاوربانک', + 'description' => 'پاوربانک‌های باکیفیت برای شارژ دستگاه‌ها.', + 'no_index' => false, + 'canonical' => null, + 'parent_id' => 1, + 'status' => CategoryStatusEnum::ACTIVE, + ], + ], + ], + [ + 'id' => 5, + 'heading' => 'لوازم خانگی', + 'slug' => 'home-appliances', + 'content' => 'محصولات برقی و لوازم خانگی با کیفیت.', + 'title' => 'لوازم خانگی', + 'description' => 'لوازم خانگی متنوع و مدرن.', + 'no_index' => false, + 'canonical' => null, + 'parent_id' => null, + 'status' => CategoryStatusEnum::ACTIVE, + 'children' => [ + [ + 'id' => 6, + 'heading' => 'یخچال و فریزر', + 'slug' => 'refrigerators', + 'content' => 'انواع یخچال و فریزر با تکنولوژی روز.', + 'title' => 'یخچال و فریزر', + 'description' => 'لوازم ضروری برای نگهداری مواد غذایی.', + 'no_index' => false, + 'canonical' => null, + 'parent_id' => 5, + 'status' => CategoryStatusEnum::ACTIVE, + ], + ], + ], + ]; + + foreach ($categories as $category) { + // Remove the 'children' key before inserting + $categoryData = Arr::except($category, 'children'); + + Category::query()->updateOrCreate( + ['id' => $category['id']], + $categoryData + ); + + if (isset($category['children'])) { + $this->createChildren($category['children'], $category['id']); + } + } + } + + private function createChildren(array $children, int $parentId): void + { + foreach ($children as $child) { + $child['parent_id'] = $parentId; + + // Remove the 'children' key before inserting + $childData = Arr::except($child, 'children'); + + Category::query()->updateOrCreate( + ['id' => $child['id']], + $childData + ); + + if (isset($child['children'])) { + $this->createChildren($child['children'], $child['id']); + } + } } }