diff --git a/app/Filament/Resources/CategoryResource.php b/app/Filament/Resources/CategoryResource.php new file mode 100644 index 0000000..019cebf --- /dev/null +++ b/app/Filament/Resources/CategoryResource.php @@ -0,0 +1,86 @@ +schema([ + Forms\Components\TextInput::make('name') + ->required() + ->maxLength(255), + Forms\Components\Select::make('type') + ->required() + ->options([ + 'game' => 'Game', + 'item' => 'Item', + ]), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('name') + ->label('Name') + ->searchable(), + Tables\Columns\TextColumn::make('type') + ->label('Type') + ->searchable(), + ]) + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListCategories::route('/'), + 'create' => Pages\CreateCategory::route('/create'), + 'edit' => Pages\EditCategory::route('/{record}/edit'), + ]; + } + + public static function canViewAny(): bool + { + return auth()->user()->is_admin==true; + } +} diff --git a/app/Filament/Resources/CategoryResource/Pages/CreateCategory.php b/app/Filament/Resources/CategoryResource/Pages/CreateCategory.php new file mode 100644 index 0000000..1e4bdbf --- /dev/null +++ b/app/Filament/Resources/CategoryResource/Pages/CreateCategory.php @@ -0,0 +1,24 @@ +getResource()::getUrl('index'); + } + + protected function mutateFormDataBeforeCreate(array $data): array + { + $data['user_id'] = auth()->id(); + + return $data; + } +} diff --git a/app/Filament/Resources/CategoryResource/Pages/EditCategory.php b/app/Filament/Resources/CategoryResource/Pages/EditCategory.php new file mode 100644 index 0000000..007953b --- /dev/null +++ b/app/Filament/Resources/CategoryResource/Pages/EditCategory.php @@ -0,0 +1,24 @@ +getResource()::getUrl('index'); + } +} diff --git a/app/Filament/Resources/CategoryResource/Pages/ListCategories.php b/app/Filament/Resources/CategoryResource/Pages/ListCategories.php new file mode 100644 index 0000000..dc66bd9 --- /dev/null +++ b/app/Filament/Resources/CategoryResource/Pages/ListCategories.php @@ -0,0 +1,19 @@ +label('Create new'), + ]; + } +} diff --git a/app/Models/Category.php b/app/Models/Category.php new file mode 100644 index 0000000..529af3a --- /dev/null +++ b/app/Models/Category.php @@ -0,0 +1,23 @@ +hasMany(Item::class); + } +} diff --git a/database/migrations/2025_01_15_182450_create_categories_table.php b/database/migrations/2025_01_15_182450_create_categories_table.php new file mode 100644 index 0000000..6e5d359 --- /dev/null +++ b/database/migrations/2025_01_15_182450_create_categories_table.php @@ -0,0 +1,29 @@ +bigIncrements('id'); + $table->string('name')->required(); + $table->string('type')->required(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('categories'); + } +};