return the full path of avatar

This commit is contained in:
2024-08-28 10:54:00 +03:30
parent 1c14828c50
commit cad7d63409
2 changed files with 9 additions and 2 deletions

View File

@@ -29,7 +29,7 @@ class ProfileController extends Controller
'major' => $user->major, 'major' => $user->major,
'degree' => $user->degree, 'degree' => $user->degree,
'mobile' => $user->mobile, 'mobile' => $user->mobile,
'avatar' => $user->avatar, 'avatar' => $user->avatarUrl()
]); ]);
} }

View File

@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Spatie\Permission\Traits\HasRoles; use Spatie\Permission\Traits\HasRoles;
use Spatie\Permission\Traits\HasPermissions; use Spatie\Permission\Traits\HasPermissions;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -24,7 +25,7 @@ class User extends Authenticatable
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'name', 'email', 'password', 'username', 'first_name', 'last_name', 'position', 'mobile', 'province_id', 'city_id', 'confirmed', 'enabled', 'avatar', 'city_fa', 'province_fa', 'degree' 'name', 'email', 'major', 'password', 'username', 'first_name', 'last_name', 'position', 'mobile', 'province_id', 'city_id', 'confirmed', 'enabled', 'avatar', 'city_fa', 'province_fa', 'degree'
]; ];
/** /**
@@ -228,4 +229,10 @@ class User extends Authenticatable
{ {
return $this->hasMany('App\Models\RoadConstructionRural'); return $this->hasMany('App\Models\RoadConstructionRural');
} }
public function avatarUrl(): ?string
{
$avatar = $this->attributes['avatar'];
return $avatar == null ? null : Storage::disk('public')->url($avatar);
}
} }