Answer the question
In order to leave comments, you need to log in
Getting user via AJAX in Laravel. How can I display his avatar?
I add the user to a tape through AJAX. By default, I display it like this: {{ Storage::url( $user->avatar ) }}
. However, through AJAX this no longer works -_-
Answer the question
In order to leave comments, you need to log in
Form the full path to the avatar on the backend, and then just substitute the path.
eloquent serialization
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['avatar_url'];
public function getAvatarUrlAttribute()
{
return \Storage::url( $this->avatar );
}
}
Yes, just write the path as it is displayed in the browser and that's it, for example: '/public/storage/avatars/' +user.avatar
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question