added proper validation message for dimensions
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\Common;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Item extends FormRequest
|
||||
{
|
||||
@ -16,7 +17,9 @@ class Item extends FormRequest
|
||||
$picture = $sale_price = $purchase_price = 'nullable';
|
||||
|
||||
if ($this->files->get('picture')) {
|
||||
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
|
||||
$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');
|
||||
}
|
||||
|
||||
if ($this->request->get('sale_information') == 'true') {
|
||||
@ -28,14 +31,27 @@ class Item extends FormRequest
|
||||
}
|
||||
|
||||
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,
|
||||
'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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user