mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
Eager loading assignedTo - I have no idea why this works
This commit is contained in:
parent
890012f6c4
commit
5278dac2b0
|
@ -85,7 +85,7 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$assets = Company::scopeCompanyables(Asset::select('assets.*'))->with(
|
$assets = Company::scopeCompanyables(Asset::select('assets.*'))->with(
|
||||||
'location', 'assetstatus', 'assetlog', 'company', 'defaultLoc',
|
'location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
|
||||||
'model.category', 'model.manufacturer', 'model.fieldset','supplier');
|
'model.category', 'model.manufacturer', 'model.fieldset','supplier');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,19 +130,19 @@ class AssetsTransformer
|
||||||
public function transformAssignedTo($asset)
|
public function transformAssignedTo($asset)
|
||||||
{
|
{
|
||||||
if ($asset->checkedOutToUser()) {
|
if ($asset->checkedOutToUser()) {
|
||||||
return $asset->assignedTo ? [
|
return $asset->assigned ? [
|
||||||
'id' => (int) $asset->assignedTo->id,
|
'id' => (int) $asset->assigned->id,
|
||||||
'username' => e($asset->assignedTo->username),
|
'username' => e($asset->assigned->username),
|
||||||
'name' => e($asset->assignedTo->getFullNameAttribute()),
|
'name' => e($asset->assigned->getFullNameAttribute()),
|
||||||
'first_name'=> e($asset->assignedTo->first_name),
|
'first_name'=> e($asset->assigned->first_name),
|
||||||
'last_name'=> e($asset->assignedTo->last_name),
|
'last_name'=> e($asset->assigned->last_name),
|
||||||
'employee_number' => e($asset->assignedTo->employee_num),
|
'employee_number' => e($asset->assigned->employee_num),
|
||||||
'type' => 'user'
|
'type' => 'user'
|
||||||
] : null;
|
] : null;
|
||||||
}
|
}
|
||||||
return $asset->assignedTo ? [
|
return $asset->assigned ? [
|
||||||
'id' => $asset->assignedTo->id,
|
'id' => $asset->assigned->id,
|
||||||
'name' => $asset->assignedTo->display_name,
|
'name' => $asset->assigned->display_name,
|
||||||
'type' => $asset->assignedType()
|
'type' => $asset->assignedType()
|
||||||
] : null;
|
] : null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue