Move logic for choosing placeholder or uploaded avatar to User model
MODIFY
app/User.php
app/User.php
@@ -16,6 +16,12 @@ class User extends Authenticatable {
'password', 'remember_token',
];
+ // Accessors
+ public function getAvatarAttribute($avatar) {
+ return $avatar ? '/storage/avatars/' . $avatar : 'https://via.placeholder.com/250';
+ }
+
+ // Relations
public function spaces() {
return $this->belongsToMany(Space::class, 'user_space');
}

MODIFY
resources/views/layout.blade.php
resources/views/layout.blade.php
<li>
<dropdown>
<span slot="button">
- <img src="{{ Auth::user()->avatar ? '/storage/avatars/' . Auth::user()->avatar : 'http://placehold.it/50x50' }}" class="avatar mr-05" /> <i class="fas fa-caret-down fa-sm"></i>
+ <img src="{{ Auth::user()->avatar }}" class="avatar mr-05" /> <i class="fas fa-caret-down fa-sm"></i>
</span>
<ul slot="menu">
<li>

MODIFY
resources/views/settings.blade.php
resources/views/settings.blade.php
<div class="row__column" style="flex: 2;">
<div class="input input--small">
<label>{{ __('fields.avatar') }}</label>
- @if (Auth::user()->avatar)
- <img src="/storage/avatars/{{ Auth::user()->avatar }}" style="width: 200px; height: 200px; border-radius: 5px; object-fit: cover;" />
- @else
- <div>You don't have an avatar</div>
- @endif
+ <img src="{{ Auth::user()->avatar }}" style="width: 200px; height: 200px; border-radius: 5px; object-fit: cover;" />
<input type="file" name="avatar" />
@include('partials.validation_error', ['payload' => 'avatar'])
</div>

Move logic for choosing placeholder or uploaded avatar to User model