60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Carbon\Exceptions\InvalidFormatException;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class StorePostRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
try {
|
|
$this->merge([
|
|
'date_start' => Carbon::parse("$this->date_start_date $this->date_start_time:00")->toDateTimeString(),
|
|
'date_end' => Carbon::parse("$this->date_end_date $this->date_end_time:00")->toDateTimeString(),
|
|
'on_top' => $this->on_top ? true : false,
|
|
]);
|
|
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
|
} catch (InvalidFormatException $e) {
|
|
// On fait rien
|
|
}
|
|
|
|
return auth()->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'picture_news' => 'required|image|mimes:jpeg,png,jpg|max:1024|dimensions:max_width=380,max_height=298',
|
|
'alt_text_picture_news' => 'required|max:255',
|
|
'title' => 'required|max:255',
|
|
'text' => 'required|min:20',
|
|
'date_start' => [
|
|
'required',
|
|
'date_format:Y-m-d H:i:s',
|
|
'before:' . Carbon::now()->parse('2037-12-31')
|
|
],
|
|
'date_end' => [
|
|
'required',
|
|
'date_format:Y-m-d H:i:s',
|
|
'after:date_start',
|
|
'before:' . Carbon::now()->parse('2037-12-31')
|
|
],
|
|
'picture_home' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:max_width=1030,max_height=239',
|
|
'alt_text_picture_home' => 'required|max:255',
|
|
'on_top' => 'nullable|boolean',
|
|
];
|
|
}
|
|
}
|