65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Carbon\Exceptions\InvalidFormatException;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class StoreSlideRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
try {
|
|
$this->merge([
|
|
'date_start' => Carbon::parse("$this->date_start_date $this->date_start_time:00"),
|
|
'date_end' => Carbon::parse("$this->date_end_date $this->date_end_time:00"),
|
|
]);
|
|
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
|
} catch (InvalidFormatException $e) {
|
|
// On fait rien
|
|
}
|
|
$this->merge([
|
|
'link_new_tab' => $this->link_new_tab ? true : false
|
|
]);
|
|
if (auth()->check()) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'title' => 'required|max:255',
|
|
'text' => 'sometimes|max:255',
|
|
'picture' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048',
|
|
'link_label' => 'sometimes|max:255',
|
|
'link' => 'sometimes|max:255',
|
|
'link_new_tab' => 'required|boolean',
|
|
'slider_id' => 'required|exists:sliders,id',
|
|
'date_start' => [
|
|
'nullable',
|
|
'date_format:Y-m-d H:i:s',
|
|
'before:' . Carbon::now()->parse('2037-12-31'),
|
|
'after:' . Carbon::now()->format('Y-m-d')
|
|
],
|
|
'date_end' => [
|
|
'nullable',
|
|
'date_format:Y-m-d H:i:s',
|
|
'after:date_start_date',
|
|
'before:' . Carbon::now()->parse('2037-12-31')
|
|
],
|
|
];
|
|
}
|
|
}
|