From b6a3d988f15538dbf439abb57b2d7ca702d0c7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna-Sara=20S=C3=A9lea?= Date: Sun, 19 Jan 2025 10:28:37 +0100 Subject: [PATCH] Type: migration, model, filament --- app/Filament/Resources/TypeResource.php | 77 +++++++++++++++++++ .../TypeResource/Pages/CreateType.php | 24 ++++++ .../Resources/TypeResource/Pages/EditType.php | 24 ++++++ .../TypeResource/Pages/ListTypes.php | 19 +++++ app/Http/Controllers/TypeController.php | 10 +++ app/Models/Type.php | 22 ++++++ .../2025_01_15_182450_create_types_table.php | 28 +++++++ 7 files changed, 204 insertions(+) create mode 100644 app/Filament/Resources/TypeResource.php create mode 100644 app/Filament/Resources/TypeResource/Pages/CreateType.php create mode 100644 app/Filament/Resources/TypeResource/Pages/EditType.php create mode 100644 app/Filament/Resources/TypeResource/Pages/ListTypes.php create mode 100644 app/Http/Controllers/TypeController.php create mode 100644 app/Models/Type.php create mode 100644 database/migrations/2025_01_15_182450_create_types_table.php 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'); + } +};