Implement ticket links and blocker state
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?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('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.');
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function linkedTicketId(): int
|
||||
{
|
||||
return (int) $this->validated('linked_ticket_id');
|
||||
}
|
||||
|
||||
public function ticketLinkTypeId(): int
|
||||
{
|
||||
return (int) $this->validated('ticket_link_type_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user