refactored example request
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Project;
|
|||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
use Inertia\Response;
|
use Inertia\Response;
|
||||||
|
|
||||||
@@ -49,15 +50,21 @@ class ProjectBoardController extends Controller
|
|||||||
403,
|
403,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$validated = $request->validated();
|
||||||
|
$boardColumnId = Arr::get($validated, 'board_column_id');
|
||||||
|
$redirectRoute = Arr::get($validated, 'redirect_to') === 'backlog'
|
||||||
|
? 'projects.backlog.index'
|
||||||
|
: 'projects.board.index';
|
||||||
|
|
||||||
$destinationColumn = $project->boardColumns()
|
$destinationColumn = $project->boardColumns()
|
||||||
->find($request->boardColumnId());
|
->find($boardColumnId);
|
||||||
|
|
||||||
$originBoardColumnId = $ticket->board_column_id;
|
$originBoardColumnId = $ticket->board_column_id;
|
||||||
$originLabel = $ticket->boardColumn?->name ?? 'Backlog';
|
$originLabel = $ticket->boardColumn?->name ?? 'Backlog';
|
||||||
$destinationLabel = $destinationColumn?->name ?? 'Backlog';
|
$destinationLabel = $destinationColumn?->name ?? 'Backlog';
|
||||||
|
|
||||||
if ($ticket->board_column_id === $request->boardColumnId()) {
|
if ($ticket->board_column_id === $boardColumnId) {
|
||||||
return to_route($request->redirectRouteName(), $project)
|
return to_route($redirectRoute, $project)
|
||||||
->with('status', "{$ticket->ticket_key} already belongs to {$destinationLabel}.");
|
->with('status', "{$ticket->ticket_key} already belongs to {$destinationLabel}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +89,7 @@ class ProjectBoardController extends Controller
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return to_route($request->redirectRouteName(), $project)
|
return to_route($redirectRoute, $project)
|
||||||
->with('status', "{$ticket->ticket_key} moved to {$destinationLabel}.");
|
->with('status', "{$ticket->ticket_key} moved to {$destinationLabel}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,22 +36,4 @@ class MoveProjectTicketRequest extends FormRequest
|
|||||||
'redirect_to' => ['required', 'string', Rule::in(['backlog', 'board'])],
|
'redirect_to' => ['required', 'string', Rule::in(['backlog', 'board'])],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boardColumnId(): ?int
|
|
||||||
{
|
|
||||||
$boardColumnId = $this->validated('board_column_id');
|
|
||||||
|
|
||||||
if ($boardColumnId === null || $boardColumnId === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int) $boardColumnId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function redirectRouteName(): string
|
|
||||||
{
|
|
||||||
return $this->validated('redirect_to') === 'backlog'
|
|
||||||
? 'projects.backlog.index'
|
|
||||||
: 'projects.board.index';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user