ldc-qrcollector-back/app/Http/Requests/Bo/Urls/StoreUrlRequest.php
2026-06-25 12:32:32 +02:00

66 lines
1.7 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Urls;
use App\Enums\Users\RoleEnum;
use App\Traits\Requests\HasPictureWithSvgSupport;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Uwil\LaravelCommon\Traits\Requests\HasPicture;
class StoreUrlRequest extends FormRequest
{
use HasPicture;
use HasPictureWithSvgSupport;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
return auth('backend')->check();
}
/**
* Prepare the data for validation.
* @return void
*/
protected function prepareForValidation(): void
{
$this->mergePicture('logo');
$this->merge([
'key' => Str::slug($this->key),
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$user = auth('backend')->user();
$rules = [
'key' => 'required|string|max:45|unique:App\Models\Url,key',
'value' => 'required|url:http,https|max:255',
'title' => 'required|string|min:3|max:255',
'brand_id' => [
'required',
'integer',
'exists:App\Models\Brand,id',
!$user->role->equals(RoleEnum::conceptor) ? Rule::in($user->brands->pluck('id')) : ''
],
'image_settings' => 'required|json',
];
return \array_merge(
$rules,
$this->pictureRulesWithSvgSupport('logo', 100, 100, 500, 500, true),
);
}
}