61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Back\Sites;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* Handles authorization and validation for updating an existing Site.
|
|
*/
|
|
class UpdateSiteRequest extends StoreSiteRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
#[\Override]
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('update', $this->route('site'));
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
#[\Override]
|
|
public function rules(): array
|
|
{
|
|
/** @var \App\Models\Site $site */
|
|
$site = $this->route('site');
|
|
return array_merge(parent::rules(), [
|
|
'name' => [
|
|
'required',
|
|
'string',
|
|
'between:3,255',
|
|
Rule::unique('sites', 'name')->ignore($site->getRouteKey()),
|
|
],
|
|
'url_re7' => [
|
|
'required',
|
|
'string',
|
|
'url:http,https',
|
|
Rule::unique('sites', 'url_re7')->ignore($site->getRouteKey()),
|
|
],
|
|
'url_prod' => [
|
|
'required',
|
|
'string',
|
|
'url:http,https',
|
|
Rule::unique('sites', 'url_prod')->ignore($site->getRouteKey()),
|
|
],
|
|
'gitlab_project_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:gitlab_projects,id',
|
|
Rule::unique('sites', 'gitlab_project_id')->ignore($site->getRouteKey()),
|
|
],
|
|
]);
|
|
}
|
|
}
|