ldc-qrcollector-back/app/Http/Requests/Bo/Urls/StoreUrlRequest.php

67 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2023-03-28 14:37:49 +00:00
<?php
namespace App\Http\Requests\Bo\Urls;
use App\Enums\Users\RoleEnum;
use App\Traits\Requests\HasPictureWithSvgSupport;
2023-03-28 14:37:49 +00:00
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
2026-04-08 15:06:41 +02:00
use Illuminate\Validation\Rule;
2026-02-12 16:09:21 +01:00
use Uwil\LaravelCommon\Traits\Requests\HasPicture;
2023-03-28 14:37:49 +00:00
class StoreUrlRequest extends FormRequest
{
use HasPicture;
use HasPictureWithSvgSupport;
2023-03-28 14:37:49 +00:00
/**
* 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()
{
2026-04-08 15:06:41 +02:00
$user = auth('backend')->user();
2023-03-28 14:37:49 +00:00
$rules = [
2023-12-18 16:37:25 +01:00
'key' => 'required|string|max:45|unique:App\Models\Url,key',
'value' => 'required|url:http,https|max:255',
2023-12-18 16:37:25 +01:00
'title' => 'required|string|min:3|max:255',
2026-04-08 15:06:41 +02:00
'brand_id' => [
'required',
'integer',
'exists:App\Models\Brand,id',
!$user->role->equals(RoleEnum::conceptor) ? Rule::in($user->brands->pluck('id')) : ''
2026-04-08 15:06:41 +02:00
],
2026-02-12 16:09:21 +01:00
'image_settings' => 'required|json',
2023-03-28 14:37:49 +00:00
];
return \array_merge(
$rules,
$this->pictureRulesWithSvgSupport('logo', 100, 100, 500, 500, true),
2023-03-28 14:37:49 +00:00
);
}
}