ldc-doux/app/Http/Requests/StoreSlideRequest.php
Olivier Legat fee051a7de Squashed commit of the following:
commit c87deb1d185b5cce65e417fde124a2691e268355
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Wed Apr 13 10:58:17 2022 +0200

    Fix bug when product not published but display

commit 93de503ce91b3f36251f00340344046aa8218b36
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Wed Apr 13 10:57:11 2022 +0200

    Product in BO - Gamme required setting

commit b1da45a5fba0c4a8aacbe10d06ada6ef93e748a0
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 17:45:21 2022 +0200

    Header - Size of search picture fix bug in IOS

commit 590772a2483be51dc9e89aa44822e20eb414dca6
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 10:18:46 2022 +0200

    Slide - Remove title and text display in BO

commit 08daf95799ab591167f33dfad6a6fec37aa4090a
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 10:13:41 2022 +0200

    form Contact : add drom list if france choose

commit f5ba031076bbb51655eaa2451bce06902191c116
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 09:59:16 2022 +0200

    Add story line Svg if needed
2022-04-26 09:42:40 +02:00

73 lines
2.1 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()
{
return auth()->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
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(),
]);
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
} catch (InvalidFormatException $e) {
// On fait rien
}
$this->merge([
'title' => 'lorem title ' . rand(),
'text' => 'lorem text ' . rand(),
'link_new_tab' => $this->link_new_tab ? true : 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|dimensions:width=1920,height=812',
'alt_text_picture' => 'sometimes|max:255',
'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')
],
'date_end' => [
'nullable',
'date_format:Y-m-d H:i:s',
'after:date_start',
'before:' . Carbon::now()->parse('2037-12-31')
],
];
}
}