null, "last_name" => null ]; protected $casts = [ ]; public function getFullName() { $firstName = trim($this->attributes["first_name"] ?? ""); $lastName = trim($this->attributes["last_name"] ?? ""); $fullName = $firstName . ' ' . $lastName; $fullName = trim($fullName); // In case first name is empty, this will remove the leading space // Use the username attribute if the full name is still empty after trimming return $fullName ?: $this->attributes["username"]; } }