|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Filament\Resources; |
| 4 | + |
| 5 | +use App\Filament\Resources\LeadResource\Pages; |
| 6 | +use App\Models\Lead; |
| 7 | +use Filament\Infolists; |
| 8 | +use Filament\Infolists\Infolist; |
| 9 | +use Filament\Resources\Resource; |
| 10 | +use Filament\Tables; |
| 11 | +use Filament\Tables\Table; |
| 12 | + |
| 13 | +class LeadResource extends Resource |
| 14 | +{ |
| 15 | + protected static ?string $model = Lead::class; |
| 16 | + |
| 17 | + protected static ?string $navigationIcon = 'heroicon-o-banknotes'; |
| 18 | + |
| 19 | + protected static ?string $navigationLabel = 'Leads'; |
| 20 | + |
| 21 | + protected static ?string $pluralModelLabel = 'Leads'; |
| 22 | + |
| 23 | + public static function canCreate(): bool |
| 24 | + { |
| 25 | + return false; |
| 26 | + } |
| 27 | + |
| 28 | + public static function infolist(Infolist $infolist): Infolist |
| 29 | + { |
| 30 | + return $infolist |
| 31 | + ->schema([ |
| 32 | + Infolists\Components\Section::make('Contact Information') |
| 33 | + ->schema([ |
| 34 | + Infolists\Components\TextEntry::make('name') |
| 35 | + ->label('Name'), |
| 36 | + Infolists\Components\TextEntry::make('email') |
| 37 | + ->label('Email') |
| 38 | + ->copyable(), |
| 39 | + Infolists\Components\TextEntry::make('company') |
| 40 | + ->label('Company'), |
| 41 | + ]) |
| 42 | + ->columns(3), |
| 43 | + |
| 44 | + Infolists\Components\Section::make('Project Details') |
| 45 | + ->schema([ |
| 46 | + Infolists\Components\TextEntry::make('budget_label') |
| 47 | + ->label('Budget'), |
| 48 | + Infolists\Components\TextEntry::make('description') |
| 49 | + ->label('App Description') |
| 50 | + ->columnSpanFull(), |
| 51 | + ]), |
| 52 | + |
| 53 | + Infolists\Components\Section::make('Metadata') |
| 54 | + ->schema([ |
| 55 | + Infolists\Components\TextEntry::make('ip_address') |
| 56 | + ->label('IP Address'), |
| 57 | + Infolists\Components\TextEntry::make('created_at') |
| 58 | + ->label('Submitted') |
| 59 | + ->dateTime(), |
| 60 | + ]) |
| 61 | + ->columns(2) |
| 62 | + ->collapsed(), |
| 63 | + ]); |
| 64 | + } |
| 65 | + |
| 66 | + public static function table(Table $table): Table |
| 67 | + { |
| 68 | + return $table |
| 69 | + ->columns([ |
| 70 | + Tables\Columns\TextColumn::make('name') |
| 71 | + ->searchable() |
| 72 | + ->sortable(), |
| 73 | + |
| 74 | + Tables\Columns\TextColumn::make('email') |
| 75 | + ->searchable() |
| 76 | + ->sortable(), |
| 77 | + |
| 78 | + Tables\Columns\TextColumn::make('company') |
| 79 | + ->searchable() |
| 80 | + ->sortable(), |
| 81 | + |
| 82 | + Tables\Columns\TextColumn::make('budget_label') |
| 83 | + ->label('Budget') |
| 84 | + ->sortable(query: function ($query, string $direction) { |
| 85 | + return $query->orderBy('budget', $direction); |
| 86 | + }), |
| 87 | + |
| 88 | + Tables\Columns\TextColumn::make('created_at') |
| 89 | + ->label('Submitted') |
| 90 | + ->dateTime() |
| 91 | + ->sortable(), |
| 92 | + ]) |
| 93 | + ->filters([ |
| 94 | + Tables\Filters\SelectFilter::make('budget') |
| 95 | + ->options(Lead::BUDGETS), |
| 96 | + ]) |
| 97 | + ->actions([ |
| 98 | + Tables\Actions\ViewAction::make(), |
| 99 | + ]) |
| 100 | + ->bulkActions([ |
| 101 | + Tables\Actions\BulkActionGroup::make([ |
| 102 | + Tables\Actions\DeleteBulkAction::make(), |
| 103 | + ]), |
| 104 | + ]) |
| 105 | + ->defaultSort('created_at', 'desc'); |
| 106 | + } |
| 107 | + |
| 108 | + public static function getRelations(): array |
| 109 | + { |
| 110 | + return [ |
| 111 | + // |
| 112 | + ]; |
| 113 | + } |
| 114 | + |
| 115 | + public static function getPages(): array |
| 116 | + { |
| 117 | + return [ |
| 118 | + 'index' => Pages\ListLeads::route('/'), |
| 119 | + 'view' => Pages\ViewLead::route('/{record}'), |
| 120 | + ]; |
| 121 | + } |
| 122 | +} |
0 commit comments