ldc-ovoteam/app/Http/Requests/Back/Recipes/UpdateRecipeRequest.php

62 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\Back\Recipes;
use App\Lib\Helpers\ToolboxHelper;
use App\Services\AdminAuthService;
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, \Illuminate\Validation\Rule|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');
}
},
],
]);
}
}