ldc-cocotte/app/Http/Requests/SortOrders.php
Jérémy Munsch 3a3d993d7c
feat: ✨ Closes #46
Add orders filter with: a search bar, date filters
2024-05-15 16:58:17 +02:00

57 lines
1.5 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SortOrders extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'sort_way' => 'sometimes|in:asc,desc',
];
if ($this->routeIs('bo.orders')) {
$rules = array_merge($rules, [
'date-order-start' =>
'required_with:date-order-end|nullable|date_format:Y-m-d|before:date-order-end',
'date-order-end' => 'nullable|date_format:Y-m-d|after:date-order-start',
'date-retrait-start' =>
'required_with:date-retrait-end|nullable|date_format:Y-m-d|before:date-retrait-end',
'date-retrait-end' => 'nullable|date_format:Y-m-d|after:date-retrait-end',
]);
}
return $rules;
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'date-order-start' => trans('Date de commande'),
'date-order-end' => trans('Jusqu\'au'),
'date-retrait-start' => trans('Date de retrait'),
'date-retrait-end' => trans('Jusqu\'au'),
];
}
}