Skip to content

Commit

Permalink
feat(customer-data): add Filament resource and navigation for Custome…
Browse files Browse the repository at this point in the history
…r Data

- Implemented `CustomerDataResource` for managing customer data via Filament.
- Added navigation item under 'Société' group with direct link to a customer record.
- Replaced `dd` with `abort(404)` for better error handling in the route.
  • Loading branch information
frederic moras committed Dec 31, 2024
1 parent e2d1ce0 commit cce7f9c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
60 changes: 60 additions & 0 deletions app/Filament/Resources/CustomerDataResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\CustomerDataResource\Pages\ViewCustomerData;
use App\Models\CustomerData;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;


class CustomerDataResource extends Resource
{
protected static ?string $model = CustomerData::class;

protected static ?string $navigationIcon = 'heroicon-o-user';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('address')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone')
->tel()
->maxLength(255),
Forms\Components\Textarea::make('notes'),
]);
}

public static function getPages(): array
{
return [
'view' => ViewCustomerData::route('/{record}'),
];
}

public static function getGloballySearchableAttributes(): array
{
return ['email', 'name'];
}

public static function getNavigationLabel(): string
{
return 'Customer Data';
}

public static function shouldRegisterNavigation(): bool
{
return false;
}
}
12 changes: 11 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Providers;

use App\Models\CustomerData;
use Filament\Facades\Filament;
use Filament\Navigation\NavigationItem;
use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider;
use Route;
Expand All @@ -29,13 +31,21 @@ public function boot(): void
return redirect()->to("/mp_admin/customer-datas/{$record->id}");
}

dd('404', 'Customer Data not found.');
abort(404, 'Customer Data not found.');
});

Collection::macro('hasOneCategory', function ($key,$column) {
return $this->filter(function ($item) use ($key, $column){
return in_array($key, $item->$column);
});
});

Filament::registerNavigationItems([
NavigationItem::make('infos')
->url('/mp_admin/customer-datas/1') // Lien direct vers l'enregistrement
->icon('heroicon-o-identification') // Icône pour le menu
->group('Société') // Groupe pour organiser le menu
->sort(0), // Position dans le menu
]);
}
}

0 comments on commit cce7f9c

Please sign in to comment.