42 lines
1.2 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;
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=1000,max_height=1000';
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 [
2022-06-01 10:15:55 +03:00
'type' => 'required|string',
2017-09-14 22:21:00 +03:00
'name' => 'required|string',
2022-06-01 10:15:55 +03:00
'sale_price' => $sale_price . '|regex:/^(?=.*?[0-9])[0-9.,]+$/',
'purchase_price'=> $purchase_price . '|regex:/^(?=.*?[0-9])[0-9.,]+$/',
2020-12-08 13:38:30 +03:00
'tax_ids' => 'nullable|array',
2018-06-30 12:33:05 +03:00
'category_id' => 'nullable|integer',
'enabled' => 'integer|boolean',
2019-11-16 10:21:14 +03:00
'picture' => $picture,
2017-09-14 22:21:00 +03:00
];
}
}