From 2fc88a0e081ddd17672a68fa59513b6ecd992124 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 20 Sep 2024 14:33:26 +0100 Subject: [PATCH] Eager load adminuser Signed-off-by: snipe --- app/Http/Controllers/Api/AssetModelsController.php | 4 +++- app/Models/AssetModel.php | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 9f78193420..e1ae0c12d3 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -48,6 +48,8 @@ class AssetModelsController extends Controller 'assets_count', 'category', 'fieldset', + 'deleted_at', + 'updated_at', ]; $assetmodels = AssetModel::select([ @@ -67,7 +69,7 @@ class AssetModelsController extends Controller 'models.deleted_at', 'models.updated_at', ]) - ->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues') + ->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues','adminuser') ->withCount('assets as assets_count'); if ($request->input('status')=='deleted') { diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index c954d25c7b..0c8f8e7b3c 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -36,7 +36,6 @@ class AssetModel extends SnipeModel protected $injectUniqueIdentifier = true; use ValidatingTrait; protected $table = 'models'; - protected $hidden = ['created_by', 'deleted_at']; protected $presenter = AssetModelPresenter::class; // Declare the rules for the model validation @@ -69,7 +68,6 @@ class AssetModel extends SnipeModel 'model_number', 'name', 'notes', - 'user_id', ]; use Searchable; @@ -226,6 +224,18 @@ class AssetModel extends SnipeModel ->orderBy('created_at', 'desc'); } + /** + * Get user who created the item + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + /** * -----------------------------------------------