Skip to content

Commit

Permalink
feat: add CustomerResource and expand TestimonialResource with rating
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 19 deletions.
79 changes: 79 additions & 0 deletions app/Filament/Resources/CustomerResource.php
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'),
];
}
}
13 changes: 7 additions & 6 deletions app/Filament/Resources/RealisationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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' )
Expand Down
23 changes: 17 additions & 6 deletions app/Filament/Resources/TestimonialResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
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;
use Filament\Tables\Columns\TextColumn;

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
Expand All @@ -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')
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion app/Models/CustomMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Spatie\MediaLibrary\MediaCollections\Models\Media;

/**
*
*
*
* @property-read mixed $extension
* @property-read mixed $human_readable_size
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Realisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Spatie\MediaLibrary\ResponsiveImages\ResponsiveImageGenerator;

/**
*
*
*
* @property-read mixed $gallery_images
* @property-read mixed $image
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Testimonial.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
* @property int|null $realisation_id
* @property-read \App\Models\Realisation|null $realisation
* @method static \Illuminate\Database\Eloquent\Builder<static>|Testimonial whereRealisationId($value)
* @property int $rating
* @method static \Illuminate\Database\Eloquent\Builder<static>|Testimonial whereRating($value)
* @mixin \Eloquent
*/
class Testimonial extends Model implements HasMedia
Expand Down
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');
} );
}
};
7 changes: 5 additions & 2 deletions resources/views/components/home/realistations.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
<!-- single blog -->
<div class="col-lg-4 col-md-6 col-sm-12 col-12">
<div class="blog-three-wrapepr">
<a href="{{ route('pages.details',['realisation'=>$realisation]) }}" class="main-thumbnail" target="_blank">
<img src="{{ $realisation->image_url }}" alt="Blog_image" width="100%">


<a href="{{ route('pages.details',['realisation'=>$realisation]) }}" class="main-thumbnail" target="_blank" >
<img src="{{ $realisation->image_url }}" alt="Blog_image" width="100%" >
<span class="badge-blog">{{\App\Enums\Categories::getLabelByKey($category['key'])}}</span>
</a>

<div class="blog-body">
<div class="blog-header">
<div class="left">
Expand Down
4 changes: 1 addition & 3 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<!-- rts cta area start -->
@include('components.cta-contact')
<!-- rts cta area End -->
@php
ray($serviceRealisations);
@endphp

<!-- rts-service area start -->
@include('components.home.services',['serviceListe'=>$serviceRealisations])
<!-- rts-service area end -->
Expand Down

0 comments on commit 7d7621b

Please sign in to comment.