From aaa28583379338e37a1fe2f83bbc3b24c6d8deca Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 16 Jul 2024 12:25:19 -0700 Subject: [PATCH 1/9] battling with handling depreciation percentage and amount --- .../Controllers/DepreciationsController.php | 15 ++++++++++ app/Models/Depreciable.php | 20 ++++++++++--- ...recitation_type_to_depreciations_table.php | 28 +++++++++++++++++++ resources/views/depreciations/edit.blade.php | 8 ++++-- 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2024_07_16_184145_add_deprecitation_type_to_depreciations_table.php diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php index 57ad35fea5..77a173581f 100755 --- a/app/Http/Controllers/DepreciationsController.php +++ b/app/Http/Controllers/DepreciationsController.php @@ -63,6 +63,7 @@ class DepreciationsController extends Controller $depreciation->months = $request->input('months'); $depreciation->user_id = Auth::id(); $depreciation->depreciation_min = $request->input('depreciation_min'); + $depreciation->depreciation_type = $request->input('depreciation_type'); // Was the asset created? if ($depreciation->save()) { @@ -116,6 +117,20 @@ class DepreciationsController extends Controller // Depreciation data $depreciation->name = $request->input('name'); $depreciation->months = $request->input('months'); + + $request->validate([ + 'depreciation_min' => [ + 'required', + 'numeric', + function ($attribute, $value, $fail) use ($request) { + if ($request->input('depreciation_type') == 'percent' && ($value < 0 || $value > 100)) { + $fail('The depreciation minimum must be between 0 and 100 when depreciation type is percentage.'); + } + }, + ], + 'depreciation_type' => 'required|in:amount,percent', + ]); + $depreciation->depreciation_type = $request->input('depreciation_type'); $depreciation->depreciation_min = $request->input('depreciation_min'); // Was the asset created? diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 7211358739..f5a29d790b 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -67,7 +67,7 @@ class Depreciable extends SnipeModel * @return float|int */ public function getLinearDepreciatedValue() // TODO - for testing it might be nice to have an optional $relative_to param here, defaulted to 'now' - { + { ; if (($this->get_depreciation()) && ($this->purchase_date)) { $months_passed = ($this->purchase_date->diff(now())->m)+($this->purchase_date->diff(now())->y*12); } else { @@ -78,7 +78,7 @@ class Depreciable extends SnipeModel //if there is a floor use it if(!$this->get_depreciation()->depreciation_min == null) { - $current_value = $this->get_depreciation()->depreciation_min; + $current_value = $this->calculateDepreciation(); }else{ $current_value = 0; @@ -86,7 +86,7 @@ class Depreciable extends SnipeModel } else { // The equation here is (Purchase_Cost-Floor_min)*(Months_passed/Months_til_depreciated) - $current_value = round(($this->purchase_cost-($this->purchase_cost - ($this->get_depreciation()->depreciation_min)) * ($months_passed / $this->get_depreciation()->months)), 2); + $current_value = round(($this->purchase_cost-($this->purchase_cost - ($this->calculateDepreciation())) * ($months_passed / $this->get_depreciation()->months)), 2); } @@ -95,7 +95,7 @@ class Depreciable extends SnipeModel public function getMonthlyDepreciation(){ - return ($this->purchase_cost-$this->get_depreciation()->depreciation_min)/$this->get_depreciation()->months; + return ($this->purchase_cost-$this->calculateDepreciation())/$this->get_depreciation()->months; } @@ -188,4 +188,16 @@ class Depreciable extends SnipeModel { return new \DateTime($time); } + private function calculateDepreciation(){ + $depreciation_min = 0; + if($this->get_depreciation()->depreciation_type === 'percentage') { + $depreciation_percent= $this->get_depreciation()->depreciation_min / 100; + $depreciation_min= $this->purchase_cost * $depreciation_percent; + return $depreciation_min; + } + else{ + $depreciation_min = $this->get_depreciation()->depreciation_min; + return $depreciation_min; + } + } } diff --git a/database/migrations/2024_07_16_184145_add_deprecitation_type_to_depreciations_table.php b/database/migrations/2024_07_16_184145_add_deprecitation_type_to_depreciations_table.php new file mode 100644 index 0000000000..1a5355f739 --- /dev/null +++ b/database/migrations/2024_07_16_184145_add_deprecitation_type_to_depreciations_table.php @@ -0,0 +1,28 @@ +string('depreciation_type')->after('depreciation_min')->default('amount'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('depreciations', function (Blueprint $table) { + $table->dropColumn('depreciation_type'); + }); + } +}; diff --git a/resources/views/depreciations/edit.blade.php b/resources/views/depreciations/edit.blade.php index a5376ea692..fed28918eb 100755 --- a/resources/views/depreciations/edit.blade.php +++ b/resources/views/depreciations/edit.blade.php @@ -28,8 +28,12 @@ -
- +
+ +
{!! $errors->first('depreciation_min', '') !!}
From 48821f8391f0e06ef3837496accc446d532f5637 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 16 Jul 2024 12:58:23 -0700 Subject: [PATCH 2/9] updates transformer, api controller --- app/Http/Controllers/Api/DepreciationsController.php | 4 ++-- app/Http/Transformers/DepreciationsTransformer.php | 3 ++- app/Models/Depreciable.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index 93088bb04a..0209eae392 100644 --- a/app/Http/Controllers/Api/DepreciationsController.php +++ b/app/Http/Controllers/Api/DepreciationsController.php @@ -20,9 +20,9 @@ class DepreciationsController extends Controller public function index(Request $request) : JsonResponse | array { $this->authorize('view', Depreciation::class); - $allowed_columns = ['id','name','months','depreciation_min','created_at']; + $allowed_columns = ['id','name','months','depreciation_min', 'depreciation_type','created_at']; - $depreciations = Depreciation::select('id','name','months','depreciation_min','user_id','created_at','updated_at'); + $depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','user_id','created_at','updated_at'); if ($request->filled('search')) { $depreciations = $depreciations->TextSearch($request->input('search')); diff --git a/app/Http/Transformers/DepreciationsTransformer.php b/app/Http/Transformers/DepreciationsTransformer.php index 78a01b4c1e..87e2ddaca4 100644 --- a/app/Http/Transformers/DepreciationsTransformer.php +++ b/app/Http/Transformers/DepreciationsTransformer.php @@ -7,6 +7,7 @@ use App\Models\Depreciable; use App\Models\Depreciation; use Illuminate\Support\Facades\Gate; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Facades\Log; class DepreciationsTransformer { @@ -26,7 +27,7 @@ class DepreciationsTransformer 'id' => (int) $depreciation->id, 'name' => e($depreciation->name), 'months' => $depreciation->months.' '.trans('general.months'), - 'depreciation_min' => $depreciation->depreciation_min, + 'depreciation_min' => $depreciation->depreciation_type === 'percent' ? $depreciation->depreciation_min.'%' : $depreciation->depreciation_min, 'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime') ]; diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index f5a29d790b..540ebaf327 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -190,7 +190,7 @@ class Depreciable extends SnipeModel } private function calculateDepreciation(){ $depreciation_min = 0; - if($this->get_depreciation()->depreciation_type === 'percentage') { + if($this->get_depreciation()->depreciation_type === 'percent') { $depreciation_percent= $this->get_depreciation()->depreciation_min / 100; $depreciation_min= $this->purchase_cost * $depreciation_percent; return $depreciation_min; From 5bb47e290fe85e458ebba0ec7888020c9a35d5ba Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 16 Jul 2024 13:07:12 -0700 Subject: [PATCH 3/9] validates percentage on store and new depreciations --- app/Http/Controllers/DepreciationsController.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php index 77a173581f..549d676d0b 100755 --- a/app/Http/Controllers/DepreciationsController.php +++ b/app/Http/Controllers/DepreciationsController.php @@ -62,8 +62,21 @@ class DepreciationsController extends Controller $depreciation->name = $request->input('name'); $depreciation->months = $request->input('months'); $depreciation->user_id = Auth::id(); - $depreciation->depreciation_min = $request->input('depreciation_min'); + + $request->validate([ + 'depreciation_min' => [ + 'required', + 'numeric', + function ($attribute, $value, $fail) use ($request) { + if ($request->input('depreciation_type') == 'percent' && ($value < 0 || $value > 100)) { + $fail('The depreciation minimum must be between 0 and 100 when depreciation type is percentage.'); + } + }, + ], + 'depreciation_type' => 'required|in:amount,percent', + ]); $depreciation->depreciation_type = $request->input('depreciation_type'); + $depreciation->depreciation_min = $request->input('depreciation_min'); // Was the asset created? if ($depreciation->save()) { From ffaacc04efb2603d542b8d630711f27b6fed5894 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 16 Jul 2024 20:24:18 -0700 Subject: [PATCH 4/9] cleaned up calculateDepreciation method --- app/Models/Depreciable.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 540ebaf327..d382a65d69 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -188,16 +188,16 @@ class Depreciable extends SnipeModel { return new \DateTime($time); } - private function calculateDepreciation(){ - $depreciation_min = 0; + + private function calculateDepreciation() + { if($this->get_depreciation()->depreciation_type === 'percent') { $depreciation_percent= $this->get_depreciation()->depreciation_min / 100; $depreciation_min= $this->purchase_cost * $depreciation_percent; return $depreciation_min; } - else{ - $depreciation_min = $this->get_depreciation()->depreciation_min; - return $depreciation_min; - } + + $depreciation_min = $this->get_depreciation()->depreciation_min; + return $depreciation_min; } } From baa7e7d5615893c6277e8af1d1daa7231232ba38 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 16 Jul 2024 20:27:38 -0700 Subject: [PATCH 5/9] clean up --- app/Models/Depreciable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index d382a65d69..02b319eeb4 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -67,7 +67,7 @@ class Depreciable extends SnipeModel * @return float|int */ public function getLinearDepreciatedValue() // TODO - for testing it might be nice to have an optional $relative_to param here, defaulted to 'now' - { ; + { if (($this->get_depreciation()) && ($this->purchase_date)) { $months_passed = ($this->purchase_date->diff(now())->m)+($this->purchase_date->diff(now())->y*12); } else { @@ -76,7 +76,7 @@ class Depreciable extends SnipeModel if ($months_passed >= $this->get_depreciation()->months){ //if there is a floor use it - if(!$this->get_depreciation()->depreciation_min == null) { + if((!$this->get_depreciation()->depreciation_min) === null) { $current_value = $this->calculateDepreciation(); From d01972bbe57501a3f53857c831c45c25d390eae3 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 23 Jul 2024 11:53:59 -0700 Subject: [PATCH 6/9] adds tests for amount and percent --- app/Models/Depreciable.php | 2 +- tests/Unit/DepreciationTest.php | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 02b319eeb4..c1452728ca 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -76,7 +76,7 @@ class Depreciable extends SnipeModel if ($months_passed >= $this->get_depreciation()->months){ //if there is a floor use it - if((!$this->get_depreciation()->depreciation_min) === null) { + if($this->get_depreciation()->depreciation_min) { $current_value = $this->calculateDepreciation(); diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index 4dd8422276..e07edc6bef 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -1,10 +1,13 @@ assertEquals(5, $depreciation->models->count()); } + public function testDepreciationAmount() + { + $depreciation = Depreciation::factory()->create([ + 'depreciation_type' => 'amount', + 'depreciation_min' => 1000, + 'months'=> 36, + ]); + + $asset = Asset::factory() + ->laptopMbp() + ->create( + [ + 'category_id' => Category::factory()->assetLaptopCategory()->create(), + 'purchase_date' => now()->subDecade(), + 'purchase_cost' => 4000, + ]); + $asset->model->update([ + 'depreciation_id' => $depreciation->id, + ]); + + $asset->getLinearDepreciatedValue(); + + $this->assertEquals($depreciation->depreciation_min, $asset->getLinearDepreciatedValue()); + } + public function testDepreciationPercentage() + { + $depreciation = Depreciation::factory()->create([ + 'depreciation_type' => 'percent', + 'depreciation_min' => 50, + 'months'=> 36, + ]); + + $asset = Asset::factory() + ->laptopMbp() + ->create( + [ + 'category_id' => Category::factory()->assetLaptopCategory()->create(), + 'purchase_date' => now()->subDecade(), + 'purchase_cost' => 4000, + ]); + $asset->model->update([ + 'depreciation_id' => $depreciation->id, + ]); + + $asset->getLinearDepreciatedValue(); + + $this->assertEquals(2000, $asset->getLinearDepreciatedValue()); + } public function testADepreciationHasLicenses() { From d5c9fa823e5b029de126510f9bae5a972cce0e62 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 24 Jul 2024 11:39:33 -0700 Subject: [PATCH 7/9] adds translations --- app/Http/Controllers/DepreciationsController.php | 4 ++-- resources/lang/en-US/validation.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php index 549d676d0b..c564cc98f7 100755 --- a/app/Http/Controllers/DepreciationsController.php +++ b/app/Http/Controllers/DepreciationsController.php @@ -69,7 +69,7 @@ class DepreciationsController extends Controller 'numeric', function ($attribute, $value, $fail) use ($request) { if ($request->input('depreciation_type') == 'percent' && ($value < 0 || $value > 100)) { - $fail('The depreciation minimum must be between 0 and 100 when depreciation type is percentage.'); + $fail(trans('validation.percent')); } }, ], @@ -137,7 +137,7 @@ class DepreciationsController extends Controller 'numeric', function ($attribute, $value, $fail) use ($request) { if ($request->input('depreciation_type') == 'percent' && ($value < 0 || $value > 100)) { - $fail('The depreciation minimum must be between 0 and 100 when depreciation type is percentage.'); + $fail(trans('validation.percent')); } }, ], diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 05374e23af..45c5010717 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -72,6 +72,7 @@ return [ 'not_in' => 'The selected :attribute is invalid.', 'numeric' => 'The :attribute must be a number.', 'present' => 'The :attribute field must be present.', + 'percent' => 'The depreciation minimum must be between 0 and 100 when depreciation type is percentage.', 'valid_regex' => 'That is not a valid regex. ', 'regex' => 'The :attribute format is invalid.', 'required' => 'The :attribute field is required.', From f05d8281f3a88ec3d60cc4c56ecf169dfc77f769 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 24 Jul 2024 12:06:56 -0700 Subject: [PATCH 8/9] fixes alignment for error msg --- resources/views/depreciations/edit.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/depreciations/edit.blade.php b/resources/views/depreciations/edit.blade.php index fed28918eb..a281beebc2 100755 --- a/resources/views/depreciations/edit.blade.php +++ b/resources/views/depreciations/edit.blade.php @@ -35,6 +35,6 @@ - {!! $errors->first('depreciation_min', '') !!} + {!! $errors->first('depreciation_min', '') !!} @stop From 950fff31ed3688910191ed1d6dfa85ed2a35c41d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 24 Jul 2024 12:12:04 -0700 Subject: [PATCH 9/9] fix conflicts --- resources/lang/en-US/validation.php | 243 ++++++++++++++++++---------- 1 file changed, 157 insertions(+), 86 deletions(-) diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 45c5010717..9bc432078f 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -13,88 +13,149 @@ return [ | */ - 'accepted' => 'The :attribute must be accepted.', - 'active_url' => 'The :attribute is not a valid URL.', - 'after' => 'The :attribute must be a date after :date.', - 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', - 'alpha' => 'The :attribute may only contain letters.', - 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', - 'alpha_num' => 'The :attribute may only contain letters and numbers.', - 'array' => 'The :attribute must be an array.', - 'before' => 'The :attribute must be a date before :date.', - 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', - 'between' => [ - 'numeric' => 'The :attribute must be between :min - :max.', - 'file' => 'The :attribute must be between :min - :max kilobytes.', - 'string' => 'The :attribute must be between :min - :max characters.', - 'array' => 'The :attribute must have between :min and :max items.', + 'accepted' => 'The :attribute field must be accepted.', + 'accepted_if' => 'The :attribute field must be accepted when :other is :value.', + 'active_url' => 'The :attribute field must be a valid URL.', + 'after' => 'The :attribute field must be a date after :date.', + 'after_or_equal' => 'The :attribute field must be a date after or equal to :date.', + 'alpha' => 'The :attribute field must only contain letters.', + 'alpha_dash' => 'The :attribute field must only contain letters, numbers, dashes, and underscores.', + 'alpha_num' => 'The :attribute field must only contain letters and numbers.', + 'array' => 'The :attribute field must be an array.', + 'ascii' => 'The :attribute field must only contain single-byte alphanumeric characters and symbols.', + 'before' => 'The :attribute field must be a date before :date.', + 'before_or_equal' => 'The :attribute field must be a date before or equal to :date.', + 'between' => [ + 'array' => 'The :attribute field must have between :min and :max items.', + 'file' => 'The :attribute field must be between :min and :max kilobytes.', + 'numeric' => 'The :attribute field must be between :min and :max.', + 'string' => 'The :attribute field must be between :min and :max characters.', ], - 'boolean' => 'The :attribute must be true or false.', - 'confirmed' => 'The :attribute confirmation does not match.', - 'date' => 'The :attribute is not a valid date.', - 'date_format' => 'The :attribute does not match the format :format.', - 'different' => 'The :attribute and :other must be different.', - 'digits' => 'The :attribute must be :digits digits.', - 'digits_between' => 'The :attribute must be between :min and :max digits.', - 'dimensions' => 'The :attribute has invalid image dimensions.', - 'distinct' => 'The :attribute field has a duplicate value.', - 'email' => 'The :attribute format is invalid.', - 'exists' => 'The selected :attribute is invalid.', - 'file' => 'The :attribute must be a file.', - 'filled' => 'The :attribute field must have a value.', - 'image' => 'The :attribute must be an image.', + 'boolean' => 'The :attribute field must be true or false.', + 'can' => 'The :attribute field contains an unauthorized value.', + 'confirmed' => 'The :attribute field confirmation does not match.', + 'contains' => 'The :attribute field is missing a required value.', + 'current_password' => 'The password is incorrect.', + 'date' => 'The :attribute field must be a valid date.', + 'date_equals' => 'The :attribute field must be a date equal to :date.', + 'date_format' => 'The :attribute field must match the format :format.', + 'decimal' => 'The :attribute field must have :decimal decimal places.', + 'declined' => 'The :attribute field must be declined.', + 'declined_if' => 'The :attribute field must be declined when :other is :value.', + 'different' => 'The :attribute field and :other must be different.', + 'digits' => 'The :attribute field must be :digits digits.', + 'digits_between' => 'The :attribute field must be between :min and :max digits.', + 'dimensions' => 'The :attribute field has invalid image dimensions.', + 'distinct' => 'The :attribute field has a duplicate value.', + 'doesnt_end_with' => 'The :attribute field must not end with one of the following: :values.', + 'doesnt_start_with' => 'The :attribute field must not start with one of the following: :values.', + 'email' => 'The :attribute field must be a valid email address.', + 'ends_with' => 'The :attribute field must end with one of the following: :values.', + 'enum' => 'The selected :attribute is invalid.', + 'exists' => 'The selected :attribute is invalid.', + 'extensions' => 'The :attribute field must have one of the following extensions: :values.', + 'file' => 'The :attribute field must be a file.', + 'filled' => 'The :attribute field must have a value.', + 'gt' => [ + 'array' => 'The :attribute field must have more than :value items.', + 'file' => 'The :attribute field must be greater than :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than :value.', + 'string' => 'The :attribute field must be greater than :value characters.', + ], + 'gte' => [ + 'array' => 'The :attribute field must have :value items or more.', + 'file' => 'The :attribute field must be greater than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be greater than or equal to :value.', + 'string' => 'The :attribute field must be greater than or equal to :value characters.', + ], + 'hex_color' => 'The :attribute field must be a valid hexadecimal color.', + 'image' => 'The :attribute field must be an image.', 'import_field_empty' => 'The value for :fieldname cannot be null.', - 'in' => 'The selected :attribute is invalid.', - 'in_array' => 'The :attribute field does not exist in :other.', - 'integer' => 'The :attribute must be an integer.', - 'ip' => 'The :attribute must be a valid IP address.', - 'ipv4' => 'The :attribute must be a valid IPv4 address.', - 'ipv6' => 'The :attribute must be a valid IPv6 address.', - 'is_unique_department' => 'The :attribute must be unique to this Company Location', - 'json' => 'The :attribute must be a valid JSON string.', - 'max' => [ - 'numeric' => 'The :attribute may not be greater than :max.', - 'file' => 'The :attribute may not be greater than :max kilobytes.', - 'string' => 'The :attribute may not be greater than :max characters.', - 'array' => 'The :attribute may not have more than :max items.', + 'in' => 'The selected :attribute is invalid.', + 'in_array' => 'The :attribute field must exist in :other.', + 'integer' => 'The :attribute field must be an integer.', + 'ip' => 'The :attribute field must be a valid IP address.', + 'ipv4' => 'The :attribute field must be a valid IPv4 address.', + 'ipv6' => 'The :attribute field must be a valid IPv6 address.', + 'json' => 'The :attribute field must be a valid JSON string.', + 'list' => 'The :attribute field must be a list.', + 'lowercase' => 'The :attribute field must be lowercase.', + 'lt' => [ + 'array' => 'The :attribute field must have less than :value items.', + 'file' => 'The :attribute field must be less than :value kilobytes.', + 'numeric' => 'The :attribute field must be less than :value.', + 'string' => 'The :attribute field must be less than :value characters.', ], - 'mimes' => 'The :attribute must be a file of type: :values.', - 'mimetypes' => 'The :attribute must be a file of type: :values.', - 'min' => [ - 'numeric' => 'The :attribute must be at least :min.', - 'file' => 'The :attribute must be at least :min kilobytes.', - 'string' => 'The :attribute must be at least :min characters.', - 'array' => 'The :attribute must have at least :min items.', + 'lte' => [ + 'array' => 'The :attribute field must not have more than :value items.', + 'file' => 'The :attribute field must be less than or equal to :value kilobytes.', + 'numeric' => 'The :attribute field must be less than or equal to :value.', + 'string' => 'The :attribute field must be less than or equal to :value characters.', ], - 'starts_with' => 'The :attribute must start with one of the following: :values.', - 'ends_with' => 'The :attribute must end with one of the following: :values.', - - 'not_in' => 'The selected :attribute is invalid.', - 'numeric' => 'The :attribute must be a number.', - 'present' => 'The :attribute field must be present.', - 'percent' => 'The depreciation minimum must be between 0 and 100 when depreciation type is percentage.', - 'valid_regex' => 'That is not a valid regex. ', - 'regex' => 'The :attribute format is invalid.', - 'required' => 'The :attribute field is required.', - 'required_if' => 'The :attribute field is required when :other is :value.', - 'required_unless' => 'The :attribute field is required unless :other is in :values.', - 'required_with' => 'The :attribute field is required when :values is present.', - 'required_with_all' => 'The :attribute field is required when :values is present.', - 'required_without' => 'The :attribute field is required when :values is not present.', + 'mac_address' => 'The :attribute field must be a valid MAC address.', + 'max' => [ + 'array' => 'The :attribute field must not have more than :max items.', + 'file' => 'The :attribute field must not be greater than :max kilobytes.', + 'numeric' => 'The :attribute field must not be greater than :max.', + 'string' => 'The :attribute field must not be greater than :max characters.', + ], + 'max_digits' => 'The :attribute field must not have more than :max digits.', + 'mimes' => 'The :attribute field must be a file of type: :values.', + 'mimetypes' => 'The :attribute field must be a file of type: :values.', + 'min' => [ + 'array' => 'The :attribute field must have at least :min items.', + 'file' => 'The :attribute field must be at least :min kilobytes.', + 'numeric' => 'The :attribute field must be at least :min.', + 'string' => 'The :attribute field must be at least :min characters.', + ], + 'min_digits' => 'The :attribute field must have at least :min digits.', + 'missing' => 'The :attribute field must be missing.', + 'missing_if' => 'The :attribute field must be missing when :other is :value.', + 'missing_unless' => 'The :attribute field must be missing unless :other is :value.', + 'missing_with' => 'The :attribute field must be missing when :values is present.', + 'missing_with_all' => 'The :attribute field must be missing when :values are present.', + 'multiple_of' => 'The :attribute field must be a multiple of :value.', + 'not_in' => 'The selected :attribute is invalid.', + 'not_regex' => 'The :attribute field format is invalid.', + 'numeric' => 'The :attribute field must be a number.', + 'password' => [ + 'letters' => 'The :attribute field must contain at least one letter.', + 'mixed' => 'The :attribute field must contain at least one uppercase and one lowercase letter.', + 'numbers' => 'The :attribute field must contain at least one number.', + 'symbols' => 'The :attribute field must contain at least one symbol.', + 'uncompromised' => 'The given :attribute has appeared in a data leak. Please choose a different :attribute.', + ], + 'percent' => 'The depreciation minimum must be between 0 and 100 when depreciation type is percentage.', + 'present' => 'The :attribute field must be present.', + 'present_if' => 'The :attribute field must be present when :other is :value.', + 'present_unless' => 'The :attribute field must be present unless :other is :value.', + 'present_with' => 'The :attribute field must be present when :values is present.', + 'present_with_all' => 'The :attribute field must be present when :values are present.', + 'prohibited' => 'The :attribute field is prohibited.', + 'prohibited_if' => 'The :attribute field is prohibited when :other is :value.', + 'prohibited_unless' => 'The :attribute field is prohibited unless :other is in :values.', + 'prohibits' => 'The :attribute field prohibits :other from being present.', + 'regex' => 'The :attribute field format is invalid.', + 'required' => 'The :attribute field is required.', + 'required_array_keys' => 'The :attribute field must contain entries for: :values.', + 'required_if' => 'The :attribute field is required when :other is :value.', + 'required_if_accepted' => 'The :attribute field is required when :other is accepted.', + 'required_if_declined' => 'The :attribute field is required when :other is declined.', + 'required_unless' => 'The :attribute field is required unless :other is in :values.', + 'required_with' => 'The :attribute field is required when :values is present.', + 'required_with_all' => 'The :attribute field is required when :values are present.', + 'required_without' => 'The :attribute field is required when :values is not present.', 'required_without_all' => 'The :attribute field is required when none of :values are present.', - 'same' => 'The :attribute and :other must match.', - 'size' => [ - 'numeric' => 'The :attribute must be :size.', - 'file' => 'The :attribute must be :size kilobytes.', - 'string' => 'The :attribute must be :size characters.', - 'array' => 'The :attribute must contain :size items.', + 'same' => 'The :attribute field must match :other.', + 'size' => [ + 'array' => 'The :attribute field must contain :size items.', + 'file' => 'The :attribute field must be :size kilobytes.', + 'numeric' => 'The :attribute field must be :size.', + 'string' => 'The :attribute field must be :size characters.', ], + 'starts_with' => 'The :attribute field must start with one of the following: :values.', 'string' => 'The :attribute must be a string.', - 'timezone' => 'The :attribute must be a valid zone.', 'two_column_unique_undeleted' => 'The :attribute must be unique across :table1 and :table2. ', - 'unique' => 'The :attribute has already been taken.', - 'uploaded' => 'The :attribute failed to upload.', - 'url' => 'The :attribute format is invalid.', 'unique_undeleted' => 'The :attribute must be unique.', 'non_circular' => 'The :attribute must not create a circular reference.', 'not_array' => ':attribute cannot be an array.', @@ -103,12 +164,13 @@ return [ 'numbers' => 'Password must contain at least one number.', 'case_diff' => 'Password must use mixed case.', 'symbols' => 'Password must contain symbols.', - 'gte' => [ - 'numeric' => 'Value cannot be negative' - ], - 'checkboxes' => ':attribute contains invalid options.', - 'radio_buttons' => ':attribute is invalid.', - + 'timezone' => 'The :attribute field must be a valid timezone.', + 'unique' => 'The :attribute has already been taken.', + 'uploaded' => 'The :attribute failed to upload.', + 'uppercase' => 'The :attribute field must be uppercase.', + 'url' => 'The :attribute field must be a valid URL.', + 'ulid' => 'The :attribute field must be a valid ULID.', + 'uuid' => 'The :attribute field must be a valid UUID.', /* |-------------------------------------------------------------------------- @@ -130,7 +192,7 @@ return [ // date_format validation with slightly less stupid messages. It duplicates a lot, but it gets the job done :( // We use this because the default error message for date_format is reflects php Y-m-d, which non-PHP - // people won't know how to format. + // people won't know how to format. 'purchase_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', 'last_audit_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD hh:mm:ss format', 'expiration_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', @@ -138,9 +200,10 @@ return [ 'expected_checkin.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', 'start_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', 'end_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', - - ], - + 'checkboxes' => ':attribute contains invalid options.', + 'radio_buttons' => ':attribute is invalid.', + 'invalid_value_in_field' => 'Invalid value included in this field', + ], /* |-------------------------------------------------------------------------- | Custom Validation Attributes @@ -156,8 +219,16 @@ return [ /* |-------------------------------------------------------------------------- - | Generic Validation Messages + | Generic Validation Messages - we use these in the jquery validation where we don't have + | access to the :attribute |-------------------------------------------------------------------------- */ - 'invalid_value_in_field' => 'Invalid value included in this field', + + 'generic' => [ + 'invalid_value_in_field' => 'Invalid value included in this field', + 'required' => 'This field is required', + 'email' => 'Please enter a valid email address', + ], + + ];