diff --git a/app/Filament/Resources/TypeResource.php b/app/Filament/Resources/TypeResource.php new file mode 100644 index 0000000..bad17a1 --- /dev/null +++ b/app/Filament/Resources/TypeResource.php @@ -0,0 +1,77 @@ +schema([ + Forms\Components\TextInput::make('name') + ->required() + ->maxLength(255), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('name') + ->label('Namn') + ->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\ListTypes::route('/'), + 'create' => Pages\CreateType::route('/create'), + 'edit' => Pages\EditType::route('/{record}/edit'), + ]; + } + + public static function canViewAny(): bool + { + return auth()->user()->is_admin==true; + } +} diff --git a/app/Filament/Resources/TypeResource/Pages/CreateType.php b/app/Filament/Resources/TypeResource/Pages/CreateType.php new file mode 100644 index 0000000..82ed070 --- /dev/null +++ b/app/Filament/Resources/TypeResource/Pages/CreateType.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/TypeResource/Pages/EditType.php b/app/Filament/Resources/TypeResource/Pages/EditType.php new file mode 100644 index 0000000..b68bee5 --- /dev/null +++ b/app/Filament/Resources/TypeResource/Pages/EditType.php @@ -0,0 +1,24 @@ +getResource()::getUrl('index'); + } +} diff --git a/app/Filament/Resources/TypeResource/Pages/ListTypes.php b/app/Filament/Resources/TypeResource/Pages/ListTypes.php new file mode 100644 index 0000000..9a4cf49 --- /dev/null +++ b/app/Filament/Resources/TypeResource/Pages/ListTypes.php @@ -0,0 +1,19 @@ +hasMany(Item::class); + } +} diff --git a/database/migrations/2025_01_15_182450_create_types_table.php b/database/migrations/2025_01_15_182450_create_types_table.php new file mode 100644 index 0000000..aaf08ea --- /dev/null +++ b/database/migrations/2025_01_15_182450_create_types_table.php @@ -0,0 +1,28 @@ +bigIncrements('id'); + $table->string('name')->required(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('types'); + } +};