47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\NovaCards;
|
|
|
|
use Closure;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UploadNovaCardBackgroundRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user() !== null;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$bytes = (int) config('nova_cards.validation.max_background_upload_bytes', 8 * 1024 * 1024);
|
|
$maxKilobytes = (int) ceil($bytes / 1024);
|
|
|
|
return [
|
|
'background' => [
|
|
'bail',
|
|
'required',
|
|
'file',
|
|
static function (string $attribute, mixed $value, Closure $fail): void {
|
|
if (! $value instanceof UploadedFile) {
|
|
return;
|
|
}
|
|
|
|
$path = $value->getRealPath() ?: $value->getPathname();
|
|
|
|
if (! $value->isValid() || ! is_string($path) || trim($path) === '') {
|
|
$fail('The ' . $attribute . ' upload is invalid.');
|
|
}
|
|
},
|
|
'image',
|
|
'mimes:jpeg,jpg,png,webp',
|
|
'max:' . $maxKilobytes,
|
|
Rule::dimensions()->minWidth(480)->minHeight(480),
|
|
],
|
|
];
|
|
}
|
|
} |