103 lines
2.8 KiB
PHP
Executable File
103 lines
2.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Response;
|
|
use Illuminate\Http\Request;
|
|
use App\Contracts\HttpStatusCodeInterface;
|
|
use App\Abstracts\CustomFormRequest;
|
|
use App\PhotoSlider;
|
|
use App\Rules\DateRange;
|
|
use App\Rules\PhotoSliderDateStart;
|
|
use App\Rules\PhotoSliderDateEnd;
|
|
|
|
class PhotoSliderFormValidation extends CustomFormRequest
|
|
{
|
|
private $status;
|
|
|
|
public function __construct(HttpStatusCodeInterface $httpStatusCode)
|
|
{
|
|
$this->status = $httpStatusCode;
|
|
}
|
|
|
|
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function messages()
|
|
{
|
|
return [
|
|
'dimensions' => 'Image size must be 1020 x 621'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules(Request $request)
|
|
{
|
|
/*
|
|
Input from PUT requests sent as multipart/form-data is unavailable
|
|
check thread if fixed : https://github.com/laravel/framework/issues/13457
|
|
|
|
*/
|
|
|
|
if($this->route('uuid') == null)
|
|
{
|
|
// STORE
|
|
|
|
$rules = [
|
|
'title' => 'required|max:32',
|
|
// 'description' => 'required',
|
|
// 'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
|
|
'date_start' => ['required', 'date', new DateRange($request), new PhotoSliderDateStart($request)],
|
|
'date_end' => ['required', 'date', new PhotoSliderDateEnd($request)],
|
|
];
|
|
if(is_file($request->image))
|
|
{
|
|
$rules['image'] = 'required|image|mimes:jpeg,png,jpg,gif,svg|max:100|dimensions:max_width=1020,max_height=621,min_width=1020,min_height=621';
|
|
}
|
|
else
|
|
$rules['image'] = 'required';
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
else
|
|
{
|
|
// UPDATE
|
|
|
|
$rules = [
|
|
'title' => 'required|max:32',
|
|
// 'description' => 'required',
|
|
'date_start' => ['required', 'date', new DateRange($request)],
|
|
'date_end' => 'required|date',
|
|
];
|
|
|
|
if(is_file($request->image))
|
|
{
|
|
$rules['image'] = 'image|mimes:jpeg,png,jpg,gif,svg|max:100|dimensions:max_width=1020,max_height=621,min_width=1020,min_height=621';
|
|
}
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public function response(array $errors)
|
|
{
|
|
return $this->status->unprocessableEntity('Form Validation Error',$errors);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|