From 7d7621be7cd4a2fef048d8f5bfcb99a9e33d1904 Mon Sep 17 00:00:00 2001 From: frederic moras Date: Mon, 30 Dec 2024 18:23:18 +0100 Subject: [PATCH] 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. --- app/Filament/Resources/CustomerResource.php | 79 +++++++++++++++++++ .../Resources/RealisationResource.php | 13 +-- .../Resources/TestimonialResource.php | 23 ++++-- app/Models/CustomMedia.php | 2 +- app/Models/Realisation.php | 2 +- app/Models/Testimonial.php | 2 + ...2_30_162208_add_rating_to_testimonials.php | 21 +++++ .../components/home/realistations.blade.php | 7 +- resources/views/home.blade.php | 4 +- 9 files changed, 134 insertions(+), 19 deletions(-) create mode 100644 app/Filament/Resources/CustomerResource.php create mode 100644 database/migrations/2024_12_30_162208_add_rating_to_testimonials.php diff --git a/app/Filament/Resources/CustomerResource.php b/app/Filament/Resources/CustomerResource.php new file mode 100644 index 0000000..fb7afc6 --- /dev/null +++ b/app/Filament/Resources/CustomerResource.php @@ -0,0 +1,79 @@ +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'), + ]; + } +} diff --git a/app/Filament/Resources/RealisationResource.php b/app/Filament/Resources/RealisationResource.php index e3abe1d..0474dc8 100644 --- a/app/Filament/Resources/RealisationResource.php +++ b/app/Filament/Resources/RealisationResource.php @@ -38,11 +38,12 @@ public static function form(Form $form): Form Toggle::make('published') ->label('Publier') - ->default(true), + ->default(true) + ->columnSpan(2), - Toggle::make('favorite') - ->label('Favoris') - ->default(false), +// Toggle::make('favorite') +// ->label('Favoris') +// ->default(false), TextInput::make( 'title' ) ->label( 'Titre') @@ -110,8 +111,8 @@ public static function table(Table $table): Table ->dateTime('j F Y'), BooleanColumn::make( 'published' ) ->label('Publié'), - BooleanColumn::make( 'favorite' ) - ->label('Favoris'), +// BooleanColumn::make( 'favorite' ) +// ->label('Favoris'), ] ) ->defaultSort( 'ordre', 'asc' ) diff --git a/app/Filament/Resources/TestimonialResource.php b/app/Filament/Resources/TestimonialResource.php index 070a3ea..9f00355 100644 --- a/app/Filament/Resources/TestimonialResource.php +++ b/app/Filament/Resources/TestimonialResource.php @@ -5,6 +5,7 @@ use App\Filament\Resources\TestimonialResource\Pages; use App\Models\Testimonial; use Filament\Forms; +use Filament\Forms\Components\Section; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables\Columns\BooleanColumn; @@ -12,6 +13,9 @@ use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; +use IbrahimBougaoua\FilamentRatingStar\Forms\Components\RatingStar; +use IbrahimBougaoua\FilamentRatingStar\Columns\Components\RatingStar as RatingStarColumn; + class TestimonialResource extends Resource @@ -27,23 +31,29 @@ public static function form(Form $form): Form { return $form ->schema([ + Forms\Components\Toggle::make('published') + ->label('Publier') + ->default(false) + ->columnSpan(2), Forms\Components\TextInput::make('author') ->label('Auteur') ->required() ->maxLength(255), Forms\Components\Textarea::make('content') - ->label('Contenu') + ->label('Message') ->required(), Forms\Components\TextInput::make('city') ->label('Ville') ->required() ->maxLength(255), - Forms\Components\Toggle::make('published') - ->label('Publier') - ->default(false), + Section::make() + ->schema([ + RatingStar::make('rating') + ->label('') + ]), + Forms\Components\DateTimePicker::make('created_at') - ->label('Date') - ->label('Created At'), + ->label('Date'), Forms\Components\Select::make('realisation_id') ->label('Rélisation') @@ -64,6 +74,7 @@ public static function table(Table $table): Table ->label('Contenu') ->limit(50) ->sortable(), + RatingStarColumn::make('rating')->size('sm'), TextColumn::make('city') ->label('Ville') ->sortable() diff --git a/app/Models/CustomMedia.php b/app/Models/CustomMedia.php index dd103b7..35984d7 100755 --- a/app/Models/CustomMedia.php +++ b/app/Models/CustomMedia.php @@ -8,7 +8,7 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media; /** - * + * * * @property-read mixed $extension * @property-read mixed $human_readable_size diff --git a/app/Models/Realisation.php b/app/Models/Realisation.php index 02f8cdd..f63b79b 100755 --- a/app/Models/Realisation.php +++ b/app/Models/Realisation.php @@ -13,7 +13,7 @@ use Spatie\MediaLibrary\ResponsiveImages\ResponsiveImageGenerator; /** - * + * * * @property-read mixed $gallery_images * @property-read mixed $image diff --git a/app/Models/Testimonial.php b/app/Models/Testimonial.php index 57f86d4..0f1895d 100755 --- a/app/Models/Testimonial.php +++ b/app/Models/Testimonial.php @@ -40,6 +40,8 @@ * @property int|null $realisation_id * @property-read \App\Models\Realisation|null $realisation * @method static \Illuminate\Database\Eloquent\Builder|Testimonial whereRealisationId($value) + * @property int $rating + * @method static \Illuminate\Database\Eloquent\Builder|Testimonial whereRating($value) * @mixin \Eloquent */ class Testimonial extends Model implements HasMedia diff --git a/database/migrations/2024_12_30_162208_add_rating_to_testimonials.php b/database/migrations/2024_12_30_162208_add_rating_to_testimonials.php new file mode 100644 index 0000000..2d2eb38 --- /dev/null +++ b/database/migrations/2024_12_30_162208_add_rating_to_testimonials.php @@ -0,0 +1,21 @@ +integer( 'rating')->default(5); + } ); + } + + public function down(): void + { + Schema::table( 'testimonials', function(Blueprint $table) { + $table->dropColumn( 'rating'); + } ); + } +}; diff --git a/resources/views/components/home/realistations.blade.php b/resources/views/components/home/realistations.blade.php index 6c81393..56111d2 100644 --- a/resources/views/components/home/realistations.blade.php +++ b/resources/views/components/home/realistations.blade.php @@ -20,10 +20,13 @@
- - Blog_image + + + + Blog_image {{\App\Enums\Categories::getLabelByKey($category['key'])}} +
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 4fd0e0a..f4b81d2 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -23,9 +23,7 @@ @include('components.cta-contact') - @php - ray($serviceRealisations); - @endphp + @include('components.home.services',['serviceListe'=>$serviceRealisations])