Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;

class User extends Authenticatable
{
Expand Down Expand Up @@ -34,6 +35,15 @@ class User extends Authenticatable
'remember_token',
];

/**
* The attributes that should be appended to the model's array form.
*
* @var list<string>
*/
protected $appends = [
'avatar',
];

/**
* Get the attributes that should be cast.
*
Expand All @@ -57,4 +67,18 @@ public function initials(): string
->map(fn (string $name) => Str::of($name)->substr(0, 1))
->implode('');
}

/**
* Get the URL of the user's profile photo.
*
* @return string|null
*/
public function getAvatarAttribute(): ?string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
if ($this->profile_photo_path) {
return Storage::url($this->profile_photo_path);
}

return null;
}
}
Loading