Files
KanbanGit/app/Http/Requests/StoreTicketLinkRequest.php
T
Nico Schröder 3122e00ed8
linter / quality (pull_request) Successful in 2m52s
tests / ci (8.4) (pull_request) Successful in 3m15s
fix: make project template inheritance granular and safe
2026-09-08 12:03:07 +02:00

67 lines
1.8 KiB
PHP

<?php
namespace App\Http\Requests;
use App\Models\Project;
use App\Models\Ticket;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class StoreTicketLinkRequest 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');
return [
'linked_ticket_id' => [
'required',
'integer',
Rule::exists('tickets', 'id')->where('project_id', $project->id),
],
'ticket_link_type_id' => [
'required',
'integer',
Rule::exists('ticket_link_types', 'id')->where(
fn ($query) => $query->where('project_id', $project->id),
),
],
];
}
/**
* @return array<int, callable(Validator): void>
*/
public function after(): array
{
return [
function (Validator $validator): void {
/** @var Ticket $ticket */
$ticket = $this->route('ticket');
$linkedTicketId = $this->input('linked_ticket_id');
if (is_numeric($linkedTicketId) && (int) $linkedTicketId === $ticket->id) {
$validator->errors()->add('linked_ticket_id', 'A ticket cannot be linked to itself.');
}
},
];
}
}