26
common/Auth/Traits/HasDisplayNameAttribute.php
Executable file
26
common/Auth/Traits/HasDisplayNameAttribute.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Auth\Traits;
|
||||
|
||||
trait HasDisplayNameAttribute
|
||||
{
|
||||
/**
|
||||
* Compile user display name from available attributes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayNameAttribute()
|
||||
{
|
||||
if ($this->username) {
|
||||
return $this->username;
|
||||
} else if ($this->first_name && $this->last_name) {
|
||||
return $this->first_name.' '.$this->last_name;
|
||||
} else if ($this->first_name) {
|
||||
return $this->first_name;
|
||||
} else if ($this->last_name) {
|
||||
return $this->last_name;
|
||||
} else {
|
||||
return explode('@', $this->email)[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user