45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Project;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ValidateProjectTicketBranchRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user() !== null;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
/** @var Project $project */
|
|
$project = $this->route('project');
|
|
$projectTemplateId = $project->project_template_id;
|
|
$ownershipColumn = $projectTemplateId === null ? 'project_id' : 'project_template_id';
|
|
$ownershipValue = $projectTemplateId ?? $project->id;
|
|
|
|
return [
|
|
'branch_name' => ['required', 'string', 'max:255'],
|
|
'repository_connection_id' => [
|
|
'required',
|
|
'integer',
|
|
Rule::exists('repository_connections', 'id')->where(
|
|
fn ($query) => $query->where($ownershipColumn, $ownershipValue),
|
|
),
|
|
],
|
|
];
|
|
}
|
|
}
|