Modify the getter

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2025-08-19 12:56:30 +01:00
parent 6a8e1566fe
commit 0c3103e3d2
+14 -3
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Helpers\Helper;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class SnipeModel extends Model
@@ -155,9 +156,19 @@ class SnipeModel extends Model
$this->attributes['status_id'] = $value;
}
//
public function getDisplayNameAttribute()
// This gets a little twitchy since *most* things have a property in the table called "name" (but users don't)
// AND we want to be able to use the actual display_name value from the database if it's set (usually via SCIM)
protected function displayNameAttribute(): Attribute
{
return $this->name;
// This override should only kick in if the model has a display_name property (users)
if (isset($this->display_name)) {
return Attribute::make(
get: fn (string $value) => $this->display_name,
);
}
return Attribute::make(
get: fn (string $value) => $this->name,
);
}
}