hoàn thiện upload và global search
This commit is contained in:
@@ -13,6 +13,8 @@ use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContractResource extends Resource
|
||||
{
|
||||
@@ -24,6 +26,8 @@ class ContractResource extends Resource
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'type';
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('app.resource_contracts');
|
||||
@@ -59,4 +63,34 @@ class ContractResource extends Resource
|
||||
'edit' => EditContract::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
// GlobalSearch customization
|
||||
public static function getGlobalSearchEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getGlobalSearchEloquentQuery()
|
||||
->with(['customer', 'product']);
|
||||
}
|
||||
|
||||
public static function modifyGlobalSearchQuery(Builder $query, string $search): void
|
||||
{
|
||||
$query->where('type', 'like', "%{$search}%")
|
||||
->orWhere('signed_status', 'like', "%{$search}%")
|
||||
->orWhereHas('customer', fn ($q) => $q->where('name', 'like', "%{$search}%"))
|
||||
->orWhereHas('product', fn ($q) => $q->where('name', 'like', "%{$search}%"));
|
||||
}
|
||||
|
||||
public static function getGlobalSearchResultTitle(Model $record): string
|
||||
{
|
||||
return \App\Enums\ContractType::from($record->type)->label() . ' - ' . ($record->customer?->name ?? '-');
|
||||
}
|
||||
|
||||
public static function getGlobalSearchResultDetails(Model $record): array
|
||||
{
|
||||
return [
|
||||
__('app.product') => $record->product?->name ?? '-',
|
||||
__('app.widget_customer') => $record->customer?->name ?? '-',
|
||||
__('app.blade_status') => \App\Enums\ContractStatus::from($record->status)->label(),
|
||||
__('app.signed_status') => $record->signed_status ?? '-',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomerResource extends Resource
|
||||
{
|
||||
@@ -25,6 +27,8 @@ class CustomerResource extends Resource
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('app.resource_customers');
|
||||
@@ -60,4 +64,21 @@ class CustomerResource extends Resource
|
||||
'edit' => EditCustomer::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
// GlobalSearch customization
|
||||
public static function modifyGlobalSearchQuery(Builder $query, string $search): void
|
||||
{
|
||||
$query->where('name', 'like', "%{$search}%")
|
||||
->orWhere('email', 'like', "%{$search}%")
|
||||
->orWhere('phone', 'like', "%{$search}%");
|
||||
}
|
||||
|
||||
public static function getGlobalSearchResultDetails(Model $record): array
|
||||
{
|
||||
return [
|
||||
__('app.email') => $record->email ?? '-',
|
||||
__('app.phone') => $record->phone ?? '-',
|
||||
__('app.address') => $record->address ?? '-',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ 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
|
||||
{
|
||||
@@ -25,6 +27,8 @@ class FeedbackResource extends Resource
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('app.resource_feedbacks');
|
||||
@@ -60,4 +64,34 @@ class FeedbackResource extends Resource
|
||||
'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 ?? '-',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ class EditFeedback extends EditRecord
|
||||
->multiple()
|
||||
->disk('public')
|
||||
->directory('feedback-attachments')
|
||||
->acceptedFileTypes(['image/jpeg', 'image/png', 'application/pdf', 'video/mp4', 'video/quicktime'])
|
||||
->maxSize(51200) // 50MB in KB
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
|
||||
@@ -77,6 +77,8 @@ class InteractionsRelationManager extends RelationManager
|
||||
->multiple()
|
||||
->disk('public')
|
||||
->directory('feedback-attachments')
|
||||
->acceptedFileTypes(['image/jpeg', 'image/png', 'application/pdf', 'video/mp4', 'video/quicktime'])
|
||||
->maxSize(51200) // 50MB in KB
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -197,6 +197,8 @@ class FeedbackForm
|
||||
->multiple()
|
||||
->disk('public')
|
||||
->directory('feedback-attachments')
|
||||
->acceptedFileTypes(['image/jpeg', 'image/png', 'application/pdf', 'video/mp4', 'video/quicktime'])
|
||||
->maxSize(51200) // 50MB in KB
|
||||
->columnSpan(1),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
@@ -16,6 +16,8 @@ use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductResource extends Resource
|
||||
{
|
||||
@@ -27,6 +29,8 @@ class ProductResource extends Resource
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('app.resource_products');
|
||||
@@ -64,4 +68,24 @@ class ProductResource extends Resource
|
||||
'edit' => EditProduct::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
// GlobalSearch customization
|
||||
public static function modifyGlobalSearchQuery(Builder $query, string $search): void
|
||||
{
|
||||
$query->where('name', 'like', "%{$search}%")
|
||||
->orWhere('description', 'like', "%{$search}%");
|
||||
}
|
||||
|
||||
public static function getGlobalSearchResultDetails(Model $record): array
|
||||
{
|
||||
return [
|
||||
__('app.description') => $record->description ? \Illuminate\Support\Str::limit($record->description, 50) : '-',
|
||||
__('app.blade_status') => match ($record->status) {
|
||||
'active' => __('app.status_active'),
|
||||
'inactive' => __('app.status_inactive'),
|
||||
'sold_out' => __('app.status_sold_out'),
|
||||
default => $record->status,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class RoleResource extends Resource
|
||||
@@ -59,4 +61,17 @@ class RoleResource extends Resource
|
||||
'edit' => EditRole::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
// GlobalSearch customization
|
||||
public static function modifyGlobalSearchQuery(Builder $query, string $search): void
|
||||
{
|
||||
$query->where('name', 'like', "%{$search}%");
|
||||
}
|
||||
|
||||
public static function getGlobalSearchResultDetails(Model $record): array
|
||||
{
|
||||
return [
|
||||
__('app.permissions') => $record->permissions->count() . ' quyền',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
@@ -59,4 +61,19 @@ class UserResource extends Resource
|
||||
'edit' => EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
// GlobalSearch customization
|
||||
public static function modifyGlobalSearchQuery(Builder $query, string $search): void
|
||||
{
|
||||
$query->where('name', 'like', "%{$search}%")
|
||||
->orWhere('email', 'like', "%{$search}%");
|
||||
}
|
||||
|
||||
public static function getGlobalSearchResultDetails(Model $record): array
|
||||
{
|
||||
return [
|
||||
__('app.email') => $record->email ?? '-',
|
||||
__('app.role') => ucfirst($record->role ?? '-'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user