From 1a4aebf805d7c993e3917117b276755d2f24a29c Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:45:47 +0100 Subject: [PATCH] Added TwoColumnUniqueUndeletedTrait trait Signed-off-by: snipe --- app/Models/AssetModel.php | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index 7a66620916..3c023507db 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Storage; use Watson\Validating\ValidatingTrait; use \App\Presenters\AssetModelPresenter; +use App\Http\Traits\TwoColumnUniqueUndeletedTrait; /** * Model for Asset Models. Asset Models contain higher level @@ -21,21 +22,8 @@ class AssetModel extends SnipeModel { use HasFactory; use SoftDeletes; - protected $presenter = AssetModelPresenter::class; use Loggable, Requestable, Presentable; - - protected $table = 'models'; - protected $hidden = ['user_id', 'deleted_at']; - - // Declare the rules for the model validation - protected $rules = [ - 'name' => 'string|required|min:1|max:255|unique:models,name', - 'model_number' => 'string|max:255|nullable', - 'min_amt' => 'integer|min:0|nullable', - 'category_id' => 'required|integer|exists:categories,id', - 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable', - 'eol' => 'integer:min:0|max:240|nullable', - ]; + use TwoColumnUniqueUndeletedTrait; /** * Whether the model should inject its identifier to the unique @@ -44,8 +32,26 @@ class AssetModel extends SnipeModel * * @var bool */ + protected $injectUniqueIdentifier = true; use ValidatingTrait; + protected $table = 'models'; + protected $hidden = ['user_id', 'deleted_at']; + protected $presenter = AssetModelPresenter::class; + + // Declare the rules for the model validation + + + protected $rules = [ + 'name' => 'string|required|min:1|max:255|two_column_unique_undeleted:model_number', + 'model_number' => 'string|max:255|nullable|two_column_unique_undeleted:name', + 'min_amt' => 'integer|min:0|nullable', + 'category_id' => 'required|integer|exists:categories,id', + 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable', + 'eol' => 'integer:min:0|max:240|nullable', + ]; + + /** * The attributes that are mass assignable. @@ -86,6 +92,9 @@ class AssetModel extends SnipeModel 'manufacturer' => ['name'], ]; + + + /** * Establishes the model -> assets relationship *