mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
617f58e046
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Traits;
|
||||
|
||||
use App\Models\Setting;
|
||||
|
||||
trait UniqueSerialTrait
|
||||
{
|
||||
/**
|
||||
* Prepare a unique_ids rule, adding a model identifier if required.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareUniqueSerialRule($parameters, $field)
|
||||
{
|
||||
if ($settings = Setting::getSettings()) {
|
||||
if ($settings->unique_serial == '1') {
|
||||
return 'unique_undeleted:'.$this->table.','.$this->getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ use App\Events\AssetCheckedOut;
|
|||
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;
|
||||
|
@ -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';
|
||||
|
@ -100,7 +99,7 @@ class Asset extends Depreciable
|
|||
'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',
|
||||
|
|
|
@ -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;
|
||||
|
@ -72,6 +73,17 @@ class ValidationServiceProvider extends ServiceProvider
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
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:
|
||||
|
|
|
@ -96,6 +96,7 @@ return [
|
|||
'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.',
|
||||
|
|
Loading…
Reference in a new issue