64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Back\Recipes;
|
|
|
|
use App\Services\AdminAuthService;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
use App\Lib\Helpers\ToolboxHelper;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
class UpdateRecipeRequest extends StoreRecipeRequest
|
|
{
|
|
public function __construct(
|
|
private readonly AdminAuthService $authService
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->authService->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return array_merge(parent::rules(), [
|
|
'picture' => [
|
|
'required',
|
|
function (string $attribute, mixed $value, \Closure $fail): void {
|
|
$valuePath = match (true) {
|
|
is_string($value) => $value,
|
|
$value instanceof UploadedFile => $value->getPathname(),
|
|
default => null
|
|
};
|
|
|
|
if (is_string($valuePath)) {
|
|
ToolboxHelper::validatePicture(
|
|
$attribute,
|
|
$valuePath,
|
|
$fail,
|
|
(object) [
|
|
'minWidth' => 800,
|
|
'maxWidth' => 800,
|
|
'minHeight' => 800,
|
|
'maxHeight' => 800,
|
|
]
|
|
);
|
|
} elseif ($value !== null) {
|
|
$fail('Unexpected value for picture');
|
|
}
|
|
},
|
|
],
|
|
]);
|
|
}
|
|
}
|