50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class NewsStoryRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'active' => $this->boolean('active'),
|
|
'scheduleStart' => $this->boolean('scheduleStart'),
|
|
'scheduleEnd' => $this->boolean('scheduleEnd'),
|
|
'start_publication_date' => $this->boolean('scheduleStart')
|
|
? $this->input('start_publication_date')
|
|
: now()->format('Y-m-d'),
|
|
'stop_publication_date' => $this->boolean('scheduleEnd')
|
|
? $this->input('stop_publication_date')
|
|
: '2100-01-01',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'headline' => ['required', 'string'],
|
|
'body' => ['required', 'string'],
|
|
'active' => ['required', 'boolean'],
|
|
'scheduleStart' => ['sometimes', 'boolean'],
|
|
'start_publication_date' => ['nullable', 'date'],
|
|
'scheduleEnd' => ['sometimes', 'boolean'],
|
|
'stop_publication_date' => ['nullable', 'date', 'after_or_equal:start_publication_date'],
|
|
];
|
|
}
|
|
}
|