added proper validation message for dimensions
This commit is contained in:
parent
4abd58ad1d
commit
38b2b02281
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class User extends FormRequest
|
||||
{
|
||||
@ -26,7 +27,9 @@ class User extends FormRequest
|
||||
$picture = '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');
|
||||
}
|
||||
|
||||
$email = 'required|email:rfc,dns';
|
||||
@ -59,13 +62,26 @@ class User extends FormRequest
|
||||
$password = $change_password ? '|confirmed' : '';
|
||||
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
'email' => $email,
|
||||
'current_password' => 'required_if:change_password,true' . $current_password,
|
||||
'password' => 'required_if:change_password,true' . $password,
|
||||
'companies' => $companies,
|
||||
'roles' => $roles,
|
||||
'picture' => $picture,
|
||||
'name' => 'required|string',
|
||||
'email' => $email,
|
||||
'current_password' => 'required_if:change_password,true' . $current_password,
|
||||
'password' => 'required_if:change_password,true' . $password,
|
||||
'companies' => $companies,
|
||||
'roles' => $roles,
|
||||
'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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\Common;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Company extends FormRequest
|
||||
{
|
||||
@ -16,15 +17,30 @@ class Company extends FormRequest
|
||||
$logo = 'nullable';
|
||||
|
||||
if ($this->files->get('logo')) {
|
||||
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
|
||||
$logo = 'mimes:' . config('filesystems.mimes')
|
||||
. '|between:0,' . config('filesystems.max_size') * 1024
|
||||
. '|dimensions:max_width=' . config('filesystems.max_width') . ',max_height=' . config('filesystems.max_height');
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
'email' => 'required|email:rfc,dns',
|
||||
'currency' => 'required|string',
|
||||
'domain' => 'nullable|string',
|
||||
'logo' => $logo,
|
||||
'name' => 'required|string',
|
||||
'email' => 'required|email:rfc,dns',
|
||||
'currency' => 'required|string',
|
||||
'domain' => 'nullable|string',
|
||||
'logo' => $logo,
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$logo_dimensions = trans('validation.custom.invalid_dimension', [
|
||||
'attribute' => Str::lower(trans('settings.company.logo')),
|
||||
'width' => config('filesystems.max_width'),
|
||||
'height' => config('filesystems.max_height'),
|
||||
]);
|
||||
|
||||
return [
|
||||
'logo.dimensions' => $logo_dimensions,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\Common;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Contact extends FormRequest
|
||||
{
|
||||
@ -46,17 +47,32 @@ class Contact extends FormRequest
|
||||
}
|
||||
|
||||
if ($this->files->get('logo')) {
|
||||
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
|
||||
$logo = 'mimes:' . config('filesystems.mimes')
|
||||
. '|between:0,' . config('filesystems.max_size') * 1024
|
||||
. '|dimensions:max_width=' . config('filesystems.max_width') . ',max_height=' . config('filesystems.max_height');
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'required|string',
|
||||
'name' => 'required|string',
|
||||
'email' => $email,
|
||||
'user_id' => 'integer|nullable',
|
||||
'type' => 'required|string',
|
||||
'name' => 'required|string',
|
||||
'email' => $email,
|
||||
'user_id' => 'integer|nullable',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'enabled' => 'integer|boolean',
|
||||
'logo' => $logo,
|
||||
'enabled' => 'integer|boolean',
|
||||
'logo' => $logo,
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$logo_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 [
|
||||
'logo.dimensions' => $logo_dimensions,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -46,30 +46,30 @@ class Document extends FormRequest
|
||||
$company_id = (int) $this->request->get('company_id');
|
||||
|
||||
$rules = [
|
||||
'type' => 'required|string',
|
||||
'document_number' => 'required|string|unique:documents,NULL,' . $id . ',id,type,' . $type . ',company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'status' => 'required|string',
|
||||
'issued_at' => 'required|date_format:Y-m-d H:i:s|before_or_equal:due_at',
|
||||
'due_at' => 'required|date_format:Y-m-d H:i:s|after_or_equal:issued_at',
|
||||
'amount' => 'required',
|
||||
'items.*.name' => 'required|string',
|
||||
'items.*.price' => 'required|amount',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'currency_rate' => 'required|gt:0',
|
||||
'contact_id' => 'required|integer',
|
||||
'contact_name' => 'required|string',
|
||||
'category_id' => 'required|integer',
|
||||
'company_logo' => $company_logo,
|
||||
'attachment.*' => $attachment,
|
||||
'recurring_count' => 'gte:0',
|
||||
'recurring_interval' => 'exclude_unless:recurring_frequency,custom|gt:0',
|
||||
'type' => 'required|string',
|
||||
'document_number' => 'required|string|unique:documents,NULL,' . $id . ',id,type,' . $type . ',company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'status' => 'required|string',
|
||||
'issued_at' => 'required|date_format:Y-m-d H:i:s|before_or_equal:due_at',
|
||||
'due_at' => 'required|date_format:Y-m-d H:i:s|after_or_equal:issued_at',
|
||||
'amount' => 'required',
|
||||
'items.*.name' => 'required|string',
|
||||
'items.*.price' => 'required|amount',
|
||||
'currency_code' => 'required|string|currency',
|
||||
'currency_rate' => 'required|gt:0',
|
||||
'contact_id' => 'required|integer',
|
||||
'contact_name' => 'required|string',
|
||||
'category_id' => 'required|integer',
|
||||
'company_logo' => $company_logo,
|
||||
'attachment.*' => $attachment,
|
||||
'recurring_count' => 'gte:0',
|
||||
'recurring_interval' => 'exclude_unless:recurring_frequency,custom|gt:0',
|
||||
];
|
||||
|
||||
$items = $this->request->all('items');
|
||||
|
||||
if ($items) {
|
||||
foreach ($items as $key => $item) {
|
||||
$size = 5;
|
||||
$size = 5;
|
||||
|
||||
if (Str::contains($item['quantity'], ['.', ','])) {
|
||||
$size = 7;
|
||||
@ -112,6 +112,12 @@ class Document extends FormRequest
|
||||
}
|
||||
}
|
||||
|
||||
$messages['company_logo.dimensions'] = trans('validation.custom.invalid_dimension', [
|
||||
'attribute' => Str::lower(trans('settings.company.logo')),
|
||||
'width' => '1000',
|
||||
'height' => '1000',
|
||||
]);
|
||||
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\Portal;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Profile extends FormRequest
|
||||
{
|
||||
@ -18,7 +19,9 @@ class Profile extends FormRequest
|
||||
$picture = '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');
|
||||
}
|
||||
|
||||
$email = 'required|email:rfc,dns|unique:users,email,' . $id . ',id,deleted_at,NULL';
|
||||
@ -32,11 +35,24 @@ class Profile extends FormRequest
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
'email' => $email,
|
||||
'current_password' => 'required_if:change_password,true|current_password',
|
||||
'password' => 'required_if:change_password,true|confirmed',
|
||||
'picture' => $picture,
|
||||
'name' => 'required|string',
|
||||
'email' => $email,
|
||||
'current_password' => 'required_if:change_password,true|current_password',
|
||||
'password' => 'required_if:change_password,true|confirmed',
|
||||
'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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\Setting;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Setting extends FormRequest
|
||||
{
|
||||
@ -19,18 +20,22 @@ class Setting extends FormRequest
|
||||
|
||||
switch ($prefix) {
|
||||
case 'company':
|
||||
$logo = 'mimes:' . config('filesystems.mimes')
|
||||
. '|between:0,' . config('filesystems.max_size') * 1024
|
||||
. '|dimensions:max_width=' . config('filesystems.max_width') . ',max_height=' . config('filesystems.max_height');
|
||||
|
||||
$rules = [
|
||||
'name' => 'required|string',
|
||||
'name' => 'required|string',
|
||||
'email' => 'required|email',
|
||||
'logo' => 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000',
|
||||
'logo' => $logo,
|
||||
];
|
||||
|
||||
break;
|
||||
case 'default':
|
||||
$rules = [
|
||||
'currency' => 'required|string|currency',
|
||||
'locale' => 'required|string',
|
||||
'payment_method' => 'required|string',
|
||||
'currency' => 'required|string|currency',
|
||||
'locale' => 'required|string',
|
||||
'payment_method' => 'required|string',
|
||||
];
|
||||
|
||||
break;
|
||||
@ -38,4 +43,17 @@ class Setting extends FormRequest
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$logo_dimensions = trans('validation.custom.invalid_dimension', [
|
||||
'attribute' => Str::lower(trans('settings.company.logo')),
|
||||
'width' => config('filesystems.max_width'),
|
||||
'height' => config('filesystems.max_height'),
|
||||
]);
|
||||
|
||||
return [
|
||||
'logo.dimensions' => $logo_dimensions,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace App\Http\Requests\Wizard;
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use App\Traits\Modules as RemoteModules;
|
||||
use Illuminate\Validation\Factory as ValidationFactory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Company extends FormRequest
|
||||
{
|
||||
@ -31,17 +32,32 @@ class Company extends FormRequest
|
||||
$logo = 'nullable';
|
||||
|
||||
if ($this->files->get('logo')) {
|
||||
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
|
||||
$logo = 'mimes:' . config('filesystems.mimes')
|
||||
. '|between:0,' . config('filesystems.max_size') * 1024
|
||||
. '|dimensions:max_width=' . config('filesystems.max_width') . ',max_height=' . config('filesystems.max_height');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'logo' => $logo,
|
||||
];
|
||||
|
||||
if (!setting('apps.api_key', false) && !empty($this->request->get('api_key'))) {
|
||||
if (! setting('apps.api_key', false) && ! empty($this->request->get('api_key'))) {
|
||||
$rules['api_key'] = 'string|check';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$logo_dimensions = trans('validation.custom.invalid_dimension', [
|
||||
'attribute' => Str::lower(trans('settings.company.logo')),
|
||||
'width' => config('filesystems.max_width'),
|
||||
'height' => config('filesystems.max_height'),
|
||||
]);
|
||||
|
||||
return [
|
||||
'logo.dimensions' => $logo_dimensions,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,24 @@ return [
|
||||
|
||||
'max_size' => env('FILESYSTEM_MAX_SIZE', '2'),
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed image max width, in pixes
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'max_width' => env('FILESYSTEM_MAX_WIDTH', '1000'),
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed image max height, in pixes
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'max_height' => env('FILESYSTEM_MAX_HEIGHT', '1000'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filesystem Disks
|
||||
|
@ -141,6 +141,7 @@ return [
|
||||
'invalid_currency' => 'The :attribute code is invalid.',
|
||||
'invalid_amount' => 'The amount :attribute is invalid.',
|
||||
'invalid_extension' => 'The file extension is invalid.',
|
||||
'invalid_dimension' => 'The :attribute dimensions must be max :width x :height px.',
|
||||
],
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user