-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CustomerResource and expand TestimonialResource with rating
Introduces `CustomerResource` for managing customer data in Filament. Enhances `TestimonialResource` with a rating system, including a new migration to add a `rating` column to the testimonials table. Removes unused debug code from home view.
- Loading branch information
frederic moras
committed
Dec 30, 2024
1 parent
b547a7d
commit 7d7621b
Showing
9 changed files
with
134 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\CustomerResource\Pages; | ||
use App\Models\Customer; | ||
|
||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
|
||
use Filament\Tables; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Components\Toggle; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Columns\BooleanColumn; | ||
use Filament\Tables\Table; | ||
|
||
class CustomerResource extends Resource | ||
{ | ||
protected static ?string $model = Customer::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-user'; | ||
|
||
protected static ?string $pluralLabel = 'Clients'; | ||
protected static ?string $label = 'Client'; | ||
|
||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
TextInput::make('email') | ||
->label('Email') | ||
->email() | ||
->required(), | ||
TextInput::make('nom') | ||
->label('Nom') | ||
->required(), | ||
TextInput::make('adresse') | ||
->label('Adresse') | ||
->required(), | ||
TextInput::make('phone') | ||
->label('Téléphone') | ||
->required(), | ||
Toggle::make('newsletter') | ||
->label('Abonné à la newsletter'), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('email')->label('Email')->sortable()->searchable(), | ||
TextColumn::make('nom')->label('Nom')->sortable()->searchable(), | ||
TextColumn::make('adresse')->label('Adresse')->sortable(), | ||
TextColumn::make('phone')->label('Téléphone')->sortable(), | ||
BooleanColumn::make('newsletter')->label('Newsletter'), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListCustomers::route('/'), | ||
'create' => Pages\CreateCustomer::route('/create'), | ||
'edit' => Pages\EditCustomer::route('/{record}/edit'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
database/migrations/2024_12_30_162208_add_rating_to_testimonials.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::table( 'testimonials', function(Blueprint $table) { | ||
$table->integer( 'rating')->default(5); | ||
} ); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::table( 'testimonials', function(Blueprint $table) { | ||
$table->dropColumn( 'rating'); | ||
} ); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters