- Create TaskStoreRequest, TaskUpdateRequest with authorize() + rules() - Create IssueStoreRequest, IssueUpdateRequest with authorize() + rules() - Create InspectionStoreRequest, InspectionUpdateRequest with authorize() + rules() + withValidator() - Update TaskForm to use FormRequests via app() - Update IssueForm (kept inline validation for complex logic) - Add InspectionStore/Update requests for ProjectMap inspection methods Tests: 101 passing (319 assertions)
36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Issue;
|
|
use App\Models\Project;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class IssueStoreRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
$project = $this->route('project') ?? Project::find($this->input('project_id'));
|
|
if ($project) {
|
|
return $this->user()->can('create issues', $project);
|
|
}
|
|
return $this->user()->can('create issues');
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'title' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'status' => ['required', Rule::in(Issue::STATUSES)],
|
|
'priority' => ['required', Rule::in(Issue::PRIORITIES)],
|
|
'type' => ['required', Rule::in(Issue::TYPES)],
|
|
'assignedTo' => 'nullable|exists:users,id',
|
|
'resolutionNotes' => 'nullable|string',
|
|
'featureId' => 'nullable|exists:features,id',
|
|
'inspectionId' => 'nullable|exists:inspections,id',
|
|
'project_id' => 'required|exists:projects,id',
|
|
];
|
|
}
|
|
} |