58 lines
1.8 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
2018-06-10 02:48:51 +03:00
namespace App\Http\Requests\Common;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
use App\Abstracts\Http\FormRequest;
use Illuminate\Support\Str;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
class Item extends FormRequest
2017-09-14 22:21:00 +03:00
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
2022-06-01 10:15:55 +03:00
$picture = $sale_price = $purchase_price = 'nullable';
2017-09-14 22:21:00 +03:00
2021-05-14 18:29:24 +03:00
if ($this->files->get('picture')) {
$picture = 'mimes:' . config('filesystems.mimes')
. '|between:0,' . config('filesystems.max_size') * 1024
. '|dimensions:max_width=' . config('filesystems.max_width') . ',max_height=' . config('filesystems.max_height');
2019-11-16 10:21:14 +03:00
}
2017-09-14 22:21:00 +03:00
2022-06-01 10:15:55 +03:00
if ($this->request->get('sale_information') == 'true') {
$sale_price = 'required';
}
if ($this->request->get('purchase_information') == 'true') {
$purchase_price = 'required';
}
2017-09-14 22:21:00 +03:00
return [
'type' => 'required|string',
'name' => 'required|string',
'sale_price' => $sale_price . '|regex:/^(?=.*?[0-9])[0-9.,]+$/',
'purchase_price' => $purchase_price . '|regex:/^(?=.*?[0-9])[0-9.,]+$/',
'tax_ids' => 'nullable|array',
'category_id' => 'nullable|integer',
'enabled' => 'integer|boolean',
'picture' => $picture,
];
}
public function messages()
{
$picture_dimensions = trans('validation.custom.invalid_dimension', [
'attribute' => Str::lower(trans_choice('general.pictures', 1)),
'width' => config('filesystems.max_width'),
'height' => config('filesystems.max_height'),
]);
return [
'picture.dimensions' => $picture_dimensions,
2017-09-14 22:21:00 +03:00
];
}
}