Files
minicrm/app/Filament/Resources/Feedback/FeedbackResource.php
phuongtc 96e1ce4f40
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled
hoàn thiện upload và global search
2026-05-06 04:10:14 +00:00

98 lines
3.1 KiB
PHP

<?php
namespace App\Filament\Resources\Feedback;
use App\Filament\Resources\Feedback\Pages\CreateFeedback;
use App\Filament\Resources\Feedback\Pages\EditFeedback;
use App\Filament\Resources\Feedback\Pages\ListFeedback;
use App\Filament\Resources\Feedback\RelationManagers\InteractionsRelationManager;
use App\Filament\Resources\Feedback\Schemas\FeedbackForm;
use App\Filament\Resources\Feedback\Tables\FeedbackTable;
use App\Models\Feedback;
use BackedEnum;
use Illuminate\Database\Eloquent\Model;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class FeedbackResource extends Resource
{
protected static ?string $model = Feedback::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedChatBubbleLeftRight;
protected static ?string $pluralLabel = 'app.resource_feedbacks';
protected static ?int $navigationSort = 1;
protected static ?string $recordTitleAttribute = 'title';
public static function getPluralLabel(): ?string
{
return __('app.resource_feedbacks');
}
public static function getNavigationGroup(): ?string
{
return __('app.nav_customer_care');
}
public static function form(Schema $schema): Schema
{
return FeedbackForm::configure($schema);
}
public static function table(Table $table): Table
{
return FeedbackTable::configure($table);
}
public static function getRelations(): array
{
return [
InteractionsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => ListFeedback::route('/'),
'create' => CreateFeedback::route('/create'),
'edit' => EditFeedback::route('/{record}/edit'),
];
}
// GlobalSearch customization
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery()
->with(['customer', 'customerProduct.product', 'currentDepartment']);
}
public static function modifyGlobalSearchQuery(Builder $query, string $search): void
{
$query->where('title', 'like', "%{$search}%")
->orWhere('content', 'like', "%{$search}%")
->orWhereHas('customer', fn ($q) => $q->where('name', 'like', "%{$search}%"));
}
public static function getGlobalSearchResultDetails(Model $record): array
{
return [
__('app.widget_customer') => $record->customer?->name ?? '-',
__('app.product') => $record->customerProduct?->product?->name ?? __('app.general'),
__('app.blade_status') => match ($record->status) {
'pending' => __('app.status_pending'),
'processing' => __('app.status_processing'),
'resolved' => __('app.status_resolved'),
'closed' => __('app.status_closed'),
default => $record->status,
},
__('app.department') => $record->currentDepartment?->name ?? '-',
];
}
}