Faza 3.1: CRM core — Leads, Deals, Appointments, Settings, Widgets, Users
Spatie Permission cu teams (team_foreign_key=company_id, teams=true): - migrations create_permission_tables (model_has_roles cu company_id scope) - HasRoles trait pe User - ResolveTenant middleware setează permissions team_id la tenant.id - Seed: 7 roluri default per tenant (admin/manager/receptionist/mechanic/parts_manager/accountant/marketer) Module noi: - Leads (cereri): name, phone, car/model, source, UTM, status, budget, assigned_to, acțiune "Convertește" → creează automat Client + Deal - Deals (pipeline): client/vehicle, stage (8 stage-uri), price, source, lost_reason - Posts + Appointments: post_id (boxă), master_id, date+time_start+time_end, status, color - UserResource (tenant): CRUD users cu role/status/locale; canViewAny doar pentru admin Custom Filament page "Setări" (tenant): - Brand & contact (display_name, city, phone, email) - Localizare (limba RO/RU/EN, currency, theme color picker) - Servicii & tarif (labor_rate) - Liste configurabile (services, cars) — păstrate în companies.settings JSON Widgets dashboard: - Tenant: StatsOverview (Clienți, Mașini, Cereri noi, Deal-uri active, Programări azi) - Central: PlatformStats (Companii total/active/trial, Expiră în 7 zile) Seed extins demo PSauto: - 3 posturi (Pod 1/2/3 cu culori) - 2 lead-uri demo (Alex Grosu Telegram, Irina Cojocaru WhatsApp) - 3 deal-uri demo (BMW done, Audi in_work, Porsche agree) - 2 programări (azi + mâine) Filament v5 fixes: - $navigationGroup type → string|UnitEnum|null (parent stricter signature) - Toate resources noi au tipurile corecte
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\AppointmentResource\Pages;
|
||||
use App\Models\Tenant\Appointment;
|
||||
use App\Models\Tenant\Client;
|
||||
use App\Models\Tenant\Post;
|
||||
use App\Models\Tenant\User;
|
||||
use App\Models\Tenant\Vehicle;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AppointmentResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Appointment::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-calendar-days';
|
||||
|
||||
protected static ?string $navigationLabel = 'Calendar';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'CRM';
|
||||
|
||||
protected static ?string $modelLabel = 'programare';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'programări';
|
||||
|
||||
protected static ?int $navigationSort = 7;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Forms\Components\Section::make('Când & unde')
|
||||
->columns(3)
|
||||
->schema([
|
||||
Forms\Components\DatePicker::make('date')->label('Data')->default(today())->required(),
|
||||
Forms\Components\TimePicker::make('time_start')->label('De la')->required()->seconds(false),
|
||||
Forms\Components\TimePicker::make('time_end')->label('Până la')->required()->seconds(false),
|
||||
Forms\Components\Select::make('post_id')
|
||||
->label('Pod')
|
||||
->options(fn () => Post::where('is_active', true)->orderBy('sort_order')->pluck('name', 'id'))
|
||||
->searchable(),
|
||||
Forms\Components\Select::make('master_id')
|
||||
->label('Maistru / Mecanic')
|
||||
->options(fn () => User::pluck('name', 'id'))
|
||||
->searchable(),
|
||||
Forms\Components\Select::make('status')
|
||||
->options(Appointment::STATUSES)
|
||||
->default('scheduled')
|
||||
->required(),
|
||||
]),
|
||||
Forms\Components\Section::make('Client & Auto')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('client_id')
|
||||
->label('Client')
|
||||
->options(fn () => Client::pluck('name', 'id'))
|
||||
->searchable()
|
||||
->live(),
|
||||
Forms\Components\Select::make('vehicle_id')
|
||||
->label('Auto')
|
||||
->options(fn (Forms\Get $get) => $get('client_id')
|
||||
? Vehicle::where('client_id', $get('client_id'))->pluck('plate', 'id')
|
||||
: [])
|
||||
->searchable(),
|
||||
]),
|
||||
Forms\Components\TextInput::make('title')->label('Subiect')->required()->maxLength(160),
|
||||
Forms\Components\Textarea::make('notes')->label('Notițe')->columnSpanFull()->rows(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('date')->label('Data')->date('d.m.Y')->sortable(),
|
||||
Tables\Columns\TextColumn::make('time_start')->label('De la')->time('H:i'),
|
||||
Tables\Columns\TextColumn::make('time_end')->label('Până la')->time('H:i'),
|
||||
Tables\Columns\TextColumn::make('post.name')->label('Pod')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('title')->label('Subiect')->searchable()->limit(40),
|
||||
Tables\Columns\TextColumn::make('client.name')->label('Client')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('vehicle.plate')->label('Auto')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('master.name')->label('Maistru')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->formatStateUsing(fn ($state) => Appointment::STATUSES[$state] ?? $state)
|
||||
->badge()
|
||||
->colors([
|
||||
'gray' => ['scheduled'],
|
||||
'warning' => ['arrived'],
|
||||
'success' => ['done'],
|
||||
'danger' => ['cancelled', 'no_show'],
|
||||
]),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('today')
|
||||
->label('Astăzi')
|
||||
->query(fn ($q) => $q->whereDate('date', today())),
|
||||
Tables\Filters\Filter::make('upcoming')
|
||||
->label('Viitoare')
|
||||
->query(fn ($q) => $q->where('date', '>=', today())),
|
||||
Tables\Filters\SelectFilter::make('status')->options(Appointment::STATUSES),
|
||||
Tables\Filters\SelectFilter::make('post_id')
|
||||
->label('Pod')
|
||||
->options(fn () => Post::pluck('name', 'id')),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('date', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListAppointments::route('/'),
|
||||
'create' => Pages\CreateAppointment::route('/create'),
|
||||
'edit' => Pages\EditAppointment::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\AppointmentResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\AppointmentResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAppointment extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AppointmentResource::class;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\AppointmentResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\AppointmentResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAppointment extends EditRecord
|
||||
{
|
||||
protected static string $resource = AppointmentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\AppointmentResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\AppointmentResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAppointments extends ListRecords
|
||||
{
|
||||
protected static string $resource = AppointmentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\DealResource\Pages;
|
||||
use App\Models\Tenant\Client;
|
||||
use App\Models\Tenant\Deal;
|
||||
use App\Models\Tenant\Lead;
|
||||
use App\Models\Tenant\User;
|
||||
use App\Models\Tenant\Vehicle;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class DealResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Deal::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-funnel';
|
||||
|
||||
protected static ?string $navigationLabel = 'Pipeline';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'CRM';
|
||||
|
||||
protected static ?string $modelLabel = 'deal';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'deal-uri';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Forms\Components\Section::make('Detalii')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('client_id')
|
||||
->label('Client')
|
||||
->options(fn () => Client::pluck('name', 'id'))
|
||||
->searchable()
|
||||
->required(),
|
||||
Forms\Components\Select::make('vehicle_id')
|
||||
->label('Auto')
|
||||
->options(fn (Forms\Get $get) => $get('client_id')
|
||||
? Vehicle::where('client_id', $get('client_id'))->pluck('plate', 'id')
|
||||
: [])
|
||||
->searchable(),
|
||||
Forms\Components\TextInput::make('name')->label('Subiect')->required()->maxLength(160),
|
||||
Forms\Components\TextInput::make('price')->label('Valoare')->numeric()->default(0),
|
||||
Forms\Components\Select::make('stage')
|
||||
->options(Deal::STAGES)
|
||||
->default('new')
|
||||
->required(),
|
||||
Forms\Components\Select::make('source')
|
||||
->options(Lead::SOURCES)
|
||||
->searchable(),
|
||||
Forms\Components\Select::make('assigned_to')
|
||||
->label('Responsabil')
|
||||
->options(fn () => User::pluck('name', 'id'))
|
||||
->searchable(),
|
||||
]),
|
||||
Forms\Components\Textarea::make('note')->label('Notițe')->columnSpanFull()->rows(3),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('#')->sortable(),
|
||||
Tables\Columns\TextColumn::make('name')->label('Subiect')->searchable()->limit(40),
|
||||
Tables\Columns\TextColumn::make('client.name')->label('Client')->searchable(),
|
||||
Tables\Columns\TextColumn::make('vehicle.plate')->label('Auto')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('stage')
|
||||
->formatStateUsing(fn ($state) => Deal::STAGES[$state] ?? $state)
|
||||
->badge()
|
||||
->colors([
|
||||
'gray' => ['new'],
|
||||
'info' => ['contact', 'agree'],
|
||||
'warning' => ['scheduled', 'arrived', 'in_work'],
|
||||
'success' => ['done'],
|
||||
'danger' => ['lost'],
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('price')->money('MDL')->sortable(),
|
||||
Tables\Columns\TextColumn::make('source')->label('Sursă')->formatStateUsing(fn ($state) => Lead::SOURCES[$state] ?? $state)->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('assignedTo.name')->label('Responsabil')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('created_at')->date()->sortable(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('stage')->options(Deal::STAGES),
|
||||
Tables\Filters\SelectFilter::make('assigned_to')
|
||||
->label('Responsabil')
|
||||
->options(fn () => User::pluck('name', 'id')),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDeals::route('/'),
|
||||
'create' => Pages\CreateDeal::route('/create'),
|
||||
'edit' => Pages\EditDeal::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\DealResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\DealResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateDeal extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DealResource::class;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\DealResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\DealResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditDeal extends EditRecord
|
||||
{
|
||||
protected static string $resource = DealResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\DealResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\DealResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListDeals extends ListRecords
|
||||
{
|
||||
protected static string $resource = DealResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\LeadResource\Pages;
|
||||
use App\Models\Tenant\Lead;
|
||||
use App\Models\Tenant\User;
|
||||
use Filament\Forms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class LeadResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Lead::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-inbox-arrow-down';
|
||||
|
||||
protected static ?string $navigationLabel = 'Cereri';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'CRM';
|
||||
|
||||
protected static ?string $modelLabel = 'cerere';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'cereri';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Forms\Components\Section::make('Contact')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->label('Nume')->required()->maxLength(120),
|
||||
Forms\Components\TextInput::make('phone')->label('Telefon')->tel()->required()->maxLength(40),
|
||||
Forms\Components\TextInput::make('email')->email()->maxLength(120),
|
||||
Forms\Components\Select::make('status')
|
||||
->options(Lead::STATUSES)
|
||||
->default('new')
|
||||
->required(),
|
||||
]),
|
||||
Forms\Components\Section::make('Auto')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('car')->label('Marca')->maxLength(60),
|
||||
Forms\Components\TextInput::make('model')->maxLength(60),
|
||||
]),
|
||||
Forms\Components\Textarea::make('message')->label('Mesaj client')->columnSpanFull()->rows(3),
|
||||
Forms\Components\Section::make('Sursă & Atribuire')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('source')
|
||||
->options(Lead::SOURCES)
|
||||
->searchable()
|
||||
->default('manual'),
|
||||
Forms\Components\Select::make('assigned_to')
|
||||
->label('Responsabil')
|
||||
->options(fn () => User::pluck('name', 'id'))
|
||||
->searchable(),
|
||||
Forms\Components\TextInput::make('budget')->label('Buget')->numeric(),
|
||||
]),
|
||||
Forms\Components\Section::make('Marketing (UTM)')
|
||||
->collapsed()
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('utm_source'),
|
||||
Forms\Components\TextInput::make('utm_medium'),
|
||||
Forms\Components\TextInput::make('utm_campaign'),
|
||||
Forms\Components\TextInput::make('utm_term'),
|
||||
Forms\Components\TextInput::make('utm_content'),
|
||||
]),
|
||||
Forms\Components\Textarea::make('notes')->label('Notițe interne')->columnSpanFull()->rows(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('created_at')->label('Data')->dateTime('d.m.Y H:i')->sortable(),
|
||||
Tables\Columns\TextColumn::make('name')->searchable()->sortable(),
|
||||
Tables\Columns\TextColumn::make('phone')->copyable()->searchable(),
|
||||
Tables\Columns\TextColumn::make('car')->label('Auto')->formatStateUsing(fn ($state, $record) => trim($state . ' ' . ($record->model ?? ''))),
|
||||
Tables\Columns\TextColumn::make('source')->label('Sursă')->formatStateUsing(fn ($state) => Lead::SOURCES[$state] ?? $state)->badge(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->formatStateUsing(fn ($state) => Lead::STATUSES[$state] ?? $state)
|
||||
->badge()
|
||||
->colors([
|
||||
'gray' => ['new'],
|
||||
'warning' => ['contacted', 'no_answer'],
|
||||
'info' => ['scheduled'],
|
||||
'success' => ['converted'],
|
||||
'danger' => ['lost'],
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('assignedTo.name')->label('Responsabil')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('budget')->money('MDL')->placeholder('—'),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('status')->options(Lead::STATUSES),
|
||||
Tables\Filters\SelectFilter::make('source')->options(Lead::SOURCES),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\Action::make('convert')
|
||||
->label('Convertește')
|
||||
->icon('heroicon-m-arrow-right-circle')
|
||||
->color('success')
|
||||
->visible(fn (Lead $r) => $r->status !== 'converted')
|
||||
->requiresConfirmation()
|
||||
->action(function (Lead $r) {
|
||||
$deal = $r->convert();
|
||||
Notification::make()
|
||||
->title('Convertit în deal #' . $deal->id)
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListLeads::route('/'),
|
||||
'create' => Pages\CreateLead::route('/create'),
|
||||
'edit' => Pages\EditLead::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\LeadResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\LeadResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateLead extends CreateRecord
|
||||
{
|
||||
protected static string $resource = LeadResource::class;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\LeadResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\LeadResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditLead extends EditRecord
|
||||
{
|
||||
protected static string $resource = LeadResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\LeadResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\LeadResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListLeads extends ListRecords
|
||||
{
|
||||
protected static string $resource = LeadResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\UserResource\Pages;
|
||||
use App\Models\Tenant\User;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-user-group';
|
||||
|
||||
protected static ?string $navigationLabel = 'Utilizatori';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
|
||||
|
||||
protected static ?string $modelLabel = 'utilizator';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'utilizatori';
|
||||
|
||||
protected static ?int $navigationSort = 80;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
$u = auth()->user();
|
||||
return $u && $u->role === 'admin';
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Forms\Components\Section::make('Identitate')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->label('Nume')->required()->maxLength(120),
|
||||
Forms\Components\TextInput::make('email')->email()->required()->maxLength(120),
|
||||
Forms\Components\TextInput::make('phone')->tel()->maxLength(40),
|
||||
Forms\Components\Select::make('locale')
|
||||
->options(['ro' => 'Română', 'ru' => 'Русский', 'en' => 'English'])
|
||||
->default('ro'),
|
||||
]),
|
||||
Forms\Components\Section::make('Acces')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('role')
|
||||
->label('Rol primar')
|
||||
->options([
|
||||
'admin' => 'Administrator',
|
||||
'manager' => 'Manager',
|
||||
'receptionist' => 'Recepție',
|
||||
'mechanic' => 'Mecanic',
|
||||
'parts_manager' => 'Magazioner piese',
|
||||
'accountant' => 'Contabil',
|
||||
'marketer' => 'Marketing',
|
||||
])
|
||||
->required()
|
||||
->default('mechanic'),
|
||||
Forms\Components\Select::make('status')
|
||||
->options(['active' => 'Activ', 'inactive' => 'Inactiv', 'blocked' => 'Blocat'])
|
||||
->default('active')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('password')
|
||||
->label('Parolă')
|
||||
->password()
|
||||
->required(fn (string $context) => $context === 'create')
|
||||
->dehydrated(fn ($state) => filled($state))
|
||||
->dehydrateStateUsing(fn ($state) => Hash::make($state))
|
||||
->minLength(6)
|
||||
->helperText('La editare lasă gol pentru a păstra parola actuală.'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')->searchable()->sortable(),
|
||||
Tables\Columns\TextColumn::make('email')->searchable()->copyable(),
|
||||
Tables\Columns\TextColumn::make('phone')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('role')->badge(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->colors([
|
||||
'success' => ['active'],
|
||||
'warning' => ['inactive'],
|
||||
'danger' => ['blocked'],
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('last_login_at')->dateTime()->placeholder('—')->toggleable(),
|
||||
Tables\Columns\TextColumn::make('created_at')->date()->sortable()->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('role')->options([
|
||||
'admin' => 'Admin', 'manager' => 'Manager', 'receptionist' => 'Recepție',
|
||||
'mechanic' => 'Mecanic', 'parts_manager' => 'Magazie', 'accountant' => 'Contabil', 'marketer' => 'Marketing',
|
||||
]),
|
||||
Tables\Filters\SelectFilter::make('status')->options([
|
||||
'active' => 'Activ', 'inactive' => 'Inactiv', 'blocked' => 'Blocat',
|
||||
]),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListUsers::route('/'),
|
||||
'create' => Pages\CreateUser::route('/create'),
|
||||
'edit' => Pages\EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\DeleteAction::make()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\UserResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [Actions\CreateAction::make()];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user