Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Nov 16, 2023
2 parents 0da3ef7 + 8158320 commit 617f58e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
25 changes: 0 additions & 25 deletions app/Http/Traits/UniqueSerialTrait.php

This file was deleted.

5 changes: 2 additions & 3 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Events\CheckoutableCheckedOut;
use App\Exceptions\CheckoutNotAllowed;
use App\Helpers\Helper;
use App\Http\Traits\UniqueSerialTrait;
use App\Http\Traits\UniqueUndeletedTrait;
use App\Models\Traits\Acceptable;
use App\Models\Traits\Searchable;
Expand All @@ -32,7 +31,7 @@ class Asset extends Depreciable
protected $presenter = \App\Presenters\AssetPresenter::class;

use CompanyableTrait;
use HasFactory, Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait, UniqueSerialTrait;
use HasFactory, Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait;

public const LOCATION = 'location';
public const ASSET = 'asset';
Expand Down Expand Up @@ -100,7 +99,7 @@ public function declinedCheckout(User $declinedBy, $signature)
'expected_checkin' => 'date|nullable',
'location_id' => 'exists:locations,id|nullable',
'rtd_location_id' => 'exists:locations,id|nullable',
'asset_tag' => 'required|min:1|max:255|unique_undeleted:assets,asset_tag',
'asset_tag' => 'required|min:1|max:255|unique_undeleted:assets,asset_tag|not_array',
'purchase_date' => 'date|date_format:Y-m-d|nullable',
'serial' => 'unique_serial|nullable',
'purchase_cost' => 'numeric|nullable|gte:0',
Expand Down
12 changes: 12 additions & 0 deletions app/Providers/ValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Providers;

use App\Models\Department;
use App\Models\Setting;
use DB;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rule;
Expand Down Expand Up @@ -72,6 +73,17 @@ public function boot()
}
});


Validator::extend('unique_serial', function ($attribute, $value, $parameters, $validator) {
if(Setting::getSettings()->unique_serial == '1') {
$count = DB::table('assets')->select('id')->where('serial', '=', $value)->whereNull('deleted_at')->count();

return $count < 1;
} else {
return true;
}
});

// Prevent circular references
//
// Example usage in Location model where parent_id references another Location:
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
'unique_undeleted' => 'The :attribute must be unique.',
'non_circular' => 'The :attribute must not create a circular reference.',
'not_array' => 'The :attribute field cannot be an array.',
'unique_serial' => 'The :attribute must be unique.',
'disallow_same_pwd_as_user_fields' => 'Password cannot be the same as the username.',
'letters' => 'Password must contain at least one letter.',
'numbers' => 'Password must contain at least one number.',
Expand Down

0 comments on commit 617f58e

Please sign in to comment.