From 9dbc99200bed9d10d28ccb69ee468e46e9b02d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Sat, 27 Sep 2025 13:24:45 -0300 Subject: [PATCH] Add Customer resource to Filament admin panel: Implemented Customer model, resource, and associated pages (create, edit, list). Defined customer form schema and table configuration. Added migration for customers table. --- .../Resources/Customers/CustomerResource.php | 48 +++++++++++++++++ .../Customers/Pages/CreateCustomer.php | 11 ++++ .../Customers/Pages/EditCustomer.php | 19 +++++++ .../Customers/Pages/ListCustomers.php | 19 +++++++ .../Customers/Schemas/CustomerForm.php | 44 +++++++++++++++ .../Customers/Tables/CustomersTable.php | 54 +++++++++++++++++++ app/Models/Customer.php | 27 ++++++++++ ...25_09_27_162059_create_customers_table.php | 35 ++++++++++++ 8 files changed, 257 insertions(+) create mode 100644 app/Filament/Admin/Resources/Customers/CustomerResource.php create mode 100644 app/Filament/Admin/Resources/Customers/Pages/CreateCustomer.php create mode 100644 app/Filament/Admin/Resources/Customers/Pages/EditCustomer.php create mode 100644 app/Filament/Admin/Resources/Customers/Pages/ListCustomers.php create mode 100644 app/Filament/Admin/Resources/Customers/Schemas/CustomerForm.php create mode 100644 app/Filament/Admin/Resources/Customers/Tables/CustomersTable.php create mode 100644 app/Models/Customer.php create mode 100644 database/migrations/2025_09_27_162059_create_customers_table.php diff --git a/app/Filament/Admin/Resources/Customers/CustomerResource.php b/app/Filament/Admin/Resources/Customers/CustomerResource.php new file mode 100644 index 0000000..5d0e3e0 --- /dev/null +++ b/app/Filament/Admin/Resources/Customers/CustomerResource.php @@ -0,0 +1,48 @@ + ListCustomers::route('/'), + 'create' => CreateCustomer::route('/create'), + 'edit' => EditCustomer::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Admin/Resources/Customers/Pages/CreateCustomer.php b/app/Filament/Admin/Resources/Customers/Pages/CreateCustomer.php new file mode 100644 index 0000000..267a3d0 --- /dev/null +++ b/app/Filament/Admin/Resources/Customers/Pages/CreateCustomer.php @@ -0,0 +1,11 @@ +components([ + \Filament\Forms\Components\TextInput::make('name') + ->required() + ->maxLength(255), + \Filament\Forms\Components\TextInput::make('email') + ->email() + ->required() + ->unique(ignoreRecord: true) + ->maxLength(255), + \Filament\Forms\Components\TextInput::make('phone') + ->tel() + ->maxLength(255), + \Filament\Forms\Components\Textarea::make('address') + ->maxLength(65535) + ->columnSpanFull(), + \Filament\Forms\Components\TextInput::make('city') + ->maxLength(255), + \Filament\Forms\Components\TextInput::make('country') + ->maxLength(255), + \Filament\Forms\Components\Select::make('status') + ->options([ + 'active' => 'Active', + 'inactive' => 'Inactive', + 'pending' => 'Pending', + ]) + ->default('active') + ->required(), + \Filament\Forms\Components\Textarea::make('notes') + ->maxLength(65535) + ->columnSpanFull(), + ]); + } +} diff --git a/app/Filament/Admin/Resources/Customers/Tables/CustomersTable.php b/app/Filament/Admin/Resources/Customers/Tables/CustomersTable.php new file mode 100644 index 0000000..111aad9 --- /dev/null +++ b/app/Filament/Admin/Resources/Customers/Tables/CustomersTable.php @@ -0,0 +1,54 @@ +columns([ + \Filament\Tables\Columns\TextColumn::make('name') + ->searchable() + ->sortable(), + \Filament\Tables\Columns\TextColumn::make('email') + ->searchable() + ->sortable(), + \Filament\Tables\Columns\TextColumn::make('phone') + ->searchable(), + \Filament\Tables\Columns\TextColumn::make('city') + ->searchable() + ->sortable(), + \Filament\Tables\Columns\TextColumn::make('country') + ->searchable() + ->sortable(), + \Filament\Tables\Columns\TextColumn::make('status') + ->badge() + ->color(fn (string $state): string => match ($state) { + 'active' => 'success', + 'inactive' => 'danger', + 'pending' => 'warning', + }), + \Filament\Tables\Columns\TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + // + ]) + ->recordActions([ + EditAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ]), + ]); + } +} diff --git a/app/Models/Customer.php b/app/Models/Customer.php new file mode 100644 index 0000000..bdc06b1 --- /dev/null +++ b/app/Models/Customer.php @@ -0,0 +1,27 @@ + 'datetime', + 'updated_at' => 'datetime', + ]; +} diff --git a/database/migrations/2025_09_27_162059_create_customers_table.php b/database/migrations/2025_09_27_162059_create_customers_table.php new file mode 100644 index 0000000..5919eb0 --- /dev/null +++ b/database/migrations/2025_09_27_162059_create_customers_table.php @@ -0,0 +1,35 @@ +id(); + $table->string('name'); + $table->string('email')->unique(); + $table->string('phone')->nullable(); + $table->text('address')->nullable(); + $table->string('city')->nullable(); + $table->string('country')->nullable(); + $table->enum('status', ['active', 'inactive', 'pending'])->default('active'); + $table->text('notes')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('customers'); + } +};