An attempt to make checkout accessories a multimorph relationship

This commit is contained in:
Brady Wetherington 2024-08-12 13:40:54 +01:00
parent b917489f00
commit d6eb04a815
2 changed files with 30 additions and 2 deletions

View file

@ -255,8 +255,21 @@ class Accessory extends SnipeModel
*/
public function checkouts()
{
return $this->hasMany(\App\Models\AccessoryCheckout::class, 'accessory_id')
->with('assignedTo');
return $this->morphToMany(Accessory::class, 'assignedAccessories', 'accessories_checkout', 'assigned_to', null,);
}
public function locationAssignments()
{
//I don't nkow that we'll want this, but this is a thing we can do - find the locations that have been assigned this accessory
return $this->morphedByMany(Location::class, 'accessory_assignment');
}
public function userAssignments()
{
//I don't nkow that we'll want this, but this is a thing we can do - find the locations that have been assigned this accessory
return $this->morphedByMany(User::class, 'accessory_assignment');
}
/**

View file

@ -253,6 +253,21 @@ class Location extends SnipeModel
return $this->morphMany(\App\Models\Asset::class, 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
}
public function assignedAccessories()
{
return $this->morphToMany(
Accessory::class,
'accessory_assignment',
'accessories_checkout',
'assigned_to',
'assigned_type',
null,
null,
'accessory_assignment',
true
);
}
public function setLdapOuAttribute($ldap_ou)
{
return $this->attributes['ldap_ou'] = empty($ldap_ou) ? null : $ldap_ou;