From 0c3103e3d2ffcd4b9d7cbec97c67862b076abe72 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 19 Aug 2025 12:56:30 +0100 Subject: [PATCH] Modify the getter Signed-off-by: snipe --- app/Models/SnipeModel.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php index f26946d22a..da2f5f7a01 100644 --- a/app/Models/SnipeModel.php +++ b/app/Models/SnipeModel.php @@ -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, + ); } + }