ldc-qrcollector-back/app/Http/Requests/Bo/Urls/StoreUrlRequest.php
2023-12-18 16:37:25 +01:00

59 lines
1.4 KiB
PHP

<?php
namespace App\Http\Requests\Bo\Urls;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
class StoreUrlRequest extends FormRequest
{
use HasPicture;
/**
* 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
{
$settings = json_decode($this->image_settings);
$settings->image = "";
$this->mergePicture('logo');
$this->merge([
'key' => Str::slug($this->key),
'image_settings' => json_encode($settings),
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'key' => 'required|string|max:45|unique:App\Models\Url,key',
'value' => 'required|string|max:255',
'title' => 'required|string|min:3|max:255',
'brand_id' => 'required|integer|exists:App\Models\Brand,id',
'image_settings' => 'required|string',
];
return \array_merge(
$rules,
$this->pictureRules('logo', false, 100, 100, 500, 500),
);
}
}