Eager load adminuser

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-09-20 14:33:26 +01:00
parent bc540b6564
commit 2fc88a0e08
2 changed files with 15 additions and 3 deletions

View file

@ -48,6 +48,8 @@ class AssetModelsController extends Controller
'assets_count', 'assets_count',
'category', 'category',
'fieldset', 'fieldset',
'deleted_at',
'updated_at',
]; ];
$assetmodels = AssetModel::select([ $assetmodels = AssetModel::select([
@ -67,7 +69,7 @@ class AssetModelsController extends Controller
'models.deleted_at', 'models.deleted_at',
'models.updated_at', 'models.updated_at',
]) ])
->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues') ->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues','adminuser')
->withCount('assets as assets_count'); ->withCount('assets as assets_count');
if ($request->input('status')=='deleted') { if ($request->input('status')=='deleted') {

View file

@ -36,7 +36,6 @@ class AssetModel extends SnipeModel
protected $injectUniqueIdentifier = true; protected $injectUniqueIdentifier = true;
use ValidatingTrait; use ValidatingTrait;
protected $table = 'models'; protected $table = 'models';
protected $hidden = ['created_by', 'deleted_at'];
protected $presenter = AssetModelPresenter::class; protected $presenter = AssetModelPresenter::class;
// Declare the rules for the model validation // Declare the rules for the model validation
@ -69,7 +68,6 @@ class AssetModel extends SnipeModel
'model_number', 'model_number',
'name', 'name',
'notes', 'notes',
'user_id',
]; ];
use Searchable; use Searchable;
@ -226,6 +224,18 @@ class AssetModel extends SnipeModel
->orderBy('created_at', 'desc'); ->orderBy('created_at', 'desc');
} }
/**
* Get user who created the item
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function adminuser()
{
return $this->belongsTo(\App\Models\User::class, 'created_by');
}
/** /**
* ----------------------------------------------- * -----------------------------------------------