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,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Task;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class TaskUpdateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
$task = $this->route('task') ?? Task::find($this->route('task'));
|
||||
if ($task) {
|
||||
return $this->user()->can('update', $task);
|
||||
}
|
||||
return $this->user()->can('update tasks');
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'sometimes|required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'phase_id' => 'nullable|exists:phases,id',
|
||||
'status' => ['sometimes', 'required', Rule::in(['pending', 'in_progress', 'completed', 'cancelled'])],
|
||||
'priority' => ['sometimes', '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',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user