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',
'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') {

View file

@ -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] [<snipe@snipe.net>]
* @since [v1.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function adminuser()
{
return $this->belongsTo(\App\Models\User::class, 'created_by');
}
/**
* -----------------------------------------------