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 ?? '-'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
56
app/Http/Middleware/HandleUploadErrors.php
Normal file
56
app/Http/Middleware/HandleUploadErrors.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HandleUploadErrors
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
// Check for PHP upload errors before processing
|
||||
if ($request->isMethod('POST') && $request->header('Content-Type', '') === 'application/json') {
|
||||
$content = $request->getContent();
|
||||
$data = json_decode($content, true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
// Check if any file uploads are present in the request
|
||||
$this->checkUploadLimits($data, $request);
|
||||
}
|
||||
}
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function checkUploadLimits(array $data, Request $request): void
|
||||
{
|
||||
// Check PHP upload limits
|
||||
$uploadMax = $this->parseSize(ini_get('upload_max_filesize'));
|
||||
$postMax = $this->parseSize(ini_get('post_max_size'));
|
||||
|
||||
// Log current limits for debugging
|
||||
Log::info('Upload limits', [
|
||||
'upload_max_filesize' => ini_get('upload_max_filesize'),
|
||||
'post_max_size' => ini_get('post_max_size'),
|
||||
'content_length' => $request->header('Content-Length'),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function parseSize(string $size): int
|
||||
{
|
||||
$unit = strtolower(substr($size, -1));
|
||||
$value = (int) $size;
|
||||
|
||||
return match ($unit) {
|
||||
'g' => $value * 1024 * 1024 * 1024,
|
||||
'm' => $value * 1024 * 1024,
|
||||
'k' => $value * 1024,
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
}
|
||||
60
check-upload.php
Normal file
60
check-upload.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Check PHP upload limits
|
||||
* Run: php check-upload.php
|
||||
*/
|
||||
|
||||
echo "=== PHP Upload Limits ===" . PHP_EOL;
|
||||
echo "upload_max_filesize: " . ini_get('upload_max_filesize') . PHP_EOL;
|
||||
echo "post_max_size: " . ini_get('post_max_size') . PHP_EOL;
|
||||
echo "memory_limit: " . ini_get('memory_limit') . PHP_EOL;
|
||||
echo "max_execution_time: " . ini_get('max_execution_time') . PHP_EOL;
|
||||
echo PHP_EOL;
|
||||
|
||||
// Check if limits are sufficient
|
||||
$uploadMax = parseSize(ini_get('upload_max_filesize'));
|
||||
$postMax = parseSize(ini_get('post_max_size'));
|
||||
|
||||
echo "=== Status ===" . PHP_EOL;
|
||||
echo "Max upload size: " . formatSize($uploadMax) . PHP_EOL;
|
||||
echo "Max post size: " . formatSize($postMax) . PHP_EOL;
|
||||
|
||||
if ($uploadMax < 50 * 1024 * 1024) {
|
||||
echo PHP_EOL . "WARNING: upload_max_filesize is too small!" . PHP_EOL;
|
||||
echo "Current: " . ini_get('upload_max_filesize') . PHP_EOL;
|
||||
echo "Required: 50M or higher" . PHP_EOL;
|
||||
echo PHP_EOL . "Solutions:" . PHP_EOL;
|
||||
echo "1. Edit /etc/php/8.3/cli/php.ini" . PHP_EOL;
|
||||
echo "2. Run: php -d upload_max_filesize=50M artisan serve" . PHP_EOL;
|
||||
echo "3. Use: ./start-server.sh" . PHP_EOL;
|
||||
} else {
|
||||
echo PHP_EOL . "OK: Upload limits are sufficient!" . PHP_EOL;
|
||||
}
|
||||
|
||||
function parseSize(string $size): int
|
||||
{
|
||||
$unit = strtolower(substr($size, -1));
|
||||
$value = (int) $size;
|
||||
|
||||
return match ($unit) {
|
||||
'g' => $value * 1024 * 1024 * 1024,
|
||||
'm' => $value * 1024 * 1024,
|
||||
'k' => $value * 1024,
|
||||
default => $value,
|
||||
};
|
||||
}
|
||||
|
||||
function formatSize(int $bytes): string
|
||||
{
|
||||
if ($bytes >= 1024 * 1024 * 1024) {
|
||||
return round($bytes / (1024 * 1024 * 1024), 2) . ' GB';
|
||||
}
|
||||
if ($bytes >= 1024 * 1024) {
|
||||
return round($bytes / (1024 * 1024), 2) . ' MB';
|
||||
}
|
||||
if ($bytes >= 1024) {
|
||||
return round($bytes / 1024, 2) . ' KB';
|
||||
}
|
||||
return $bytes . ' bytes';
|
||||
}
|
||||
@@ -14,6 +14,9 @@ return [
|
||||
// FileService
|
||||
'file_type_not_allowed' => 'File type :type is not allowed. Allowed: jpg, png, pdf, mp4, mov.',
|
||||
'file_size_exceeds' => 'File size exceeds :max KB.',
|
||||
'file_upload_failed' => 'File upload failed. Please check the file and try again.',
|
||||
'file_too_large' => 'File is too large. Maximum size is :max MB.',
|
||||
'file_invalid_type' => 'Invalid file type. Only accept: jpg, png, pdf, mp4, mov.',
|
||||
|
||||
// EditFeedback page
|
||||
'transfer_department' => 'Transfer Department',
|
||||
|
||||
@@ -14,6 +14,9 @@ return [
|
||||
// FileService
|
||||
'file_type_not_allowed' => 'Loại file :type không được phép. Cho phép: jpg, png, pdf, mp4, mov.',
|
||||
'file_size_exceeds' => 'Kích thước file vượt quá :max KB.',
|
||||
'file_upload_failed' => 'Tải file lên thất bại. Vui lòng kiểm tra lại file và thử lại.',
|
||||
'file_too_large' => 'File quá lớn. Kích thước tối đa là :max MB.',
|
||||
'file_invalid_type' => 'Loại file không hợp lệ. Chỉ chấp nhận: jpg, png, pdf, mp4, mov.',
|
||||
|
||||
// EditFeedback page
|
||||
'transfer_department' => 'Chuyển phòng ban',
|
||||
|
||||
6
public/.user.ini
Normal file
6
public/.user.ini
Normal file
@@ -0,0 +1,6 @@
|
||||
; PHP upload settings for AfterSales CRM
|
||||
upload_max_filesize = 50M
|
||||
post_max_size = 55M
|
||||
memory_limit = 256M
|
||||
max_execution_time = 300
|
||||
max_input_time = 300
|
||||
6
start-server.sh
Executable file
6
start-server.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Start PHP server with increased upload limits
|
||||
php -d upload_max_filesize=50M \
|
||||
-d post_max_size=55M \
|
||||
-d memory_limit=256M \
|
||||
artisan serve --host=0.0.0.0 --port=8000
|
||||
Reference in New Issue
Block a user