Merge pull request #5551 from devansh-webkul/mass-operation-request-added

Mass Operation Request Added For Rest API and Core
This commit is contained in:
Devansh 2022-01-06 18:27:05 +05:30 committed by GitHub
commit 05518fab7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 133 additions and 66 deletions

View File

@ -3,30 +3,10 @@
namespace Webkul\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Factory as ValidationFactory;
use Webkul\Core\Contracts\Validations\CommaSeperatedInteger;
class ConfigurationForm extends FormRequest
{
/*
Added custom validator.
*/
public function __construct(ValidationFactory $validationFactory)
{
/* added custom comma seperated integer validator */
$validationFactory->extend(
'comma_seperated_integer',
function ($attribute, $value, $parameters) {
$pages = explode(',', $value);
foreach($pages as $page){
if (! is_numeric($page)) {
return false;
}
}
return true;
}
);
}
/**
* Determine if the Configuraion is authorized to make this request.
*
@ -50,7 +30,7 @@ class ConfigurationForm extends FormRequest
&& ! empty(request()->input('catalog.products.storefront.products_per_page'))
) {
$this->rules = [
'catalog.products.storefront.products_per_page' => 'comma_seperated_integer',
'catalog.products.storefront.products_per_page' => [new CommaSeperatedInteger],
];
}
@ -58,7 +38,7 @@ class ConfigurationForm extends FormRequest
&& ! request()->input('general.design.admin_logo.logo_image.delete')
) {
$this->rules = array_merge($this->rules, [
'general.design.admin_logo.logo_image' => 'required|mimes:bmp,jpeg,jpg,png,webp|max:5000',
'general.design.admin_logo.logo_image' => 'required|mimes:bmp,jpeg,jpg,png,webp|max:5000',
]);
}
@ -66,7 +46,7 @@ class ConfigurationForm extends FormRequest
&& ! request()->input('general.design.admin_logo.favicon.delete')
) {
$this->rules = array_merge($this->rules, [
'general.design.admin_logo.favicon' => 'required|mimes:bmp,jpeg,jpg,png,webp|max:5000',
'general.design.admin_logo.favicon' => 'required|mimes:bmp,jpeg,jpg,png,webp|max:5000',
]);
}
@ -74,7 +54,7 @@ class ConfigurationForm extends FormRequest
&& ! request()->input('sales.invoice_setttings.invoice_slip_design.logo.delete')
) {
$this->rules = array_merge($this->rules, [
'sales.invoice_setttings.invoice_slip_design.logo' => 'required|mimes:bmp,jpeg,jpg,png,webp|max:5000',
'sales.invoice_setttings.invoice_slip_design.logo' => 'required|mimes:bmp,jpeg,jpg,png,webp|max:5000',
]);
}
@ -90,7 +70,6 @@ class ConfigurationForm extends FormRequest
{
return [
'general.design.admin_logo.logo_image.mimes' => 'Invalid file format. Use only bmp, jpeg, jpg, png and webp.',
'catalog.products.storefront.products_per_page.comma_seperated_integer' => 'The "Product Per Page" field must be numeric and may contain comma.'
];
}
@ -100,9 +79,10 @@ class ConfigurationForm extends FormRequest
public function attributes()
{
return [
'general.design.admin_logo.logo_image' => 'Logo Image',
'general.design.admin_logo.favicon' => 'Favicon Image',
'sales.invoice_setttings.invoice_slip_design.logo' => 'Invoice Logo'
'general.design.admin_logo.logo_image' => 'Logo Image',
'general.design.admin_logo.favicon' => 'Favicon Image',
'sales.invoice_setttings.invoice_slip_design.logo' => 'Invoice Logo',
'catalog.products.storefront.products_per_page' => 'Product Per Page',
];
}
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace Webkul\Core\Contracts\Validations;
use Illuminate\Contracts\Validation\Rule;
class CommaSeperatedInteger implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$integerValues = explode(',', $value);
foreach ($integerValues as $integerValue) {
if (! is_numeric($integerValue)) {
return false;
}
}
return true;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return trans('core::validation.comma-seperated-integer');
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Webkul\Core\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Webkul\Core\Contracts\Validations\CommaSeperatedInteger;
class MassOperationRequest extends FormRequest
{
/**
* Determine if the request is authorized or not.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'indexes' => ['required', new CommaSeperatedInteger],
];
}
/**
* Handle passed validations.
*
* @return void
*/
public function passedValidation()
{
$this->replace([
'indexes' => explode(',', $this->indexes),
]);
}
}

View File

@ -1,10 +1,11 @@
<?php
return [
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'The :attribute must be valid.',
'decimal' => 'The :attribute must be valid.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'The :attribute must be valid slug.',
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'The :attribute must be valid.',
'decimal' => 'The :attribute must be valid.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'The :attribute must be valid slug.',
'comma-seperated-integer' => 'The :attribute field must be numeric and may contain comma.',
];

View File

@ -1,10 +1,11 @@
<?php
return [
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'O :attribute debe ser válido.',
'decimal' => 'O :attribute debe ser válido.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'O :attribute debe tener un slug válido.',
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'O :attribute debe ser válido.',
'decimal' => 'O :attribute debe ser válido.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'O :attribute debe tener un slug válido.',
'comma-seperated-integer' => 'The :attribute field must be numeric and may contain comma.',
];

View File

@ -1,10 +1,11 @@
<?php
return [
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'The :attribute must be valid.',
'decimal' => 'The :attribute must be valid.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'The :attribute must be valid slug.',
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'The :attribute must be valid.',
'decimal' => 'The :attribute must be valid.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'The :attribute must be valid slug.',
'comma-seperated-integer' => 'The :attribute field must be numeric and may contain comma.',
];

View File

@ -1,10 +1,11 @@
<?php
return [
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => ':attribute deve essere valido.',
'decimal' => ':attribute deve essere valido.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => ':attribute deve essere uno slug valido.',
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => ':attribute deve essere valido.',
'decimal' => ':attribute deve essere valido.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => ':attribute deve essere uno slug valido.',
'comma-seperated-integer' => 'The :attribute field must be numeric and may contain comma.',
];

View File

@ -1,10 +1,11 @@
<?php
return [
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'O :attribute precisa ser válido.',
'decimal' => 'O :attribute precisa ser válido.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'O :attribute precisa ter um slug válido.',
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => 'O :attribute precisa ser válido.',
'decimal' => 'O :attribute precisa ser válido.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => 'O :attribute precisa ter um slug válido.',
'comma-seperated-integer' => 'The :attribute field must be numeric and may contain comma.',
];

View File

@ -1,10 +1,11 @@
<?php
return [
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => ':attribute değeri geçerli olmalı.',
'decimal' => ':attribute geçerli olmalı.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => ':attribute değeri geçerli bir url olmalı.',
'address' => 'The :attribute can only accept alpha, numeric, spaces, comma and dashes.',
'alpha-numeric-space' => 'The :attribute can only accept alpha, numeric and spaces.',
'code' => ':attribute değeri geçerli olmalı.',
'decimal' => ':attribute geçerli olmalı.',
'phone-number' => 'The :attribute must be valid phone number.',
'slug' => ':attribute değeri geçerli bir url olmalı.',
'comma-seperated-integer' => 'The :attribute field must be numeric and may contain comma.',
];