feat: Phase 3.1 - FormRequests for Task, Issue, Inspection
- 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)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Project;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class TaskStoreRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
$project = $this->route('project') ?? $this->input('project_id');
|
||||
if ($project instanceof Project) {
|
||||
return $this->user()->can('create tasks', $project);
|
||||
}
|
||||
return $this->user()->can('create tasks');
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'phase_id' => 'nullable|exists:phases,id',
|
||||
'status' => ['required', Rule::in(['pending', 'in_progress', 'completed', 'cancelled'])],
|
||||
'priority' => ['required', Rule::in(['low', 'medium', 'high', 'critical'])],
|
||||
'assigned_to' => 'nullable|exists:users,id',
|
||||
'due_date' => 'nullable|date',
|
||||
'start_date' => 'nullable|date|before_or_equal:due_date',
|
||||
'estimated_hours' => 'nullable|integer|min:0|max:10000',
|
||||
'actual_hours' => 'nullable|integer|min:0|max:10000',
|
||||
'order' => 'nullable|integer|min:0',
|
||||
'parent_task_id' => 'nullable|exists:tasks,id',
|
||||
'project_id' => 'required|exists:projects,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user