58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Project;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class MoveProjectTicketRequest 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 [
|
|
'board_column_id' => [
|
|
'nullable',
|
|
'integer',
|
|
Rule::exists('board_columns', 'id')->where('project_id', $project->id),
|
|
],
|
|
'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';
|
|
}
|
|
}
|