[英]How to set a default avatar in Laravel 8?
我正在尝试为我的页面创建一个默认头像,但只出现一个字符串,而不是我的图像。 这就是我所做的:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('avatar')->default('/storage/avatars/avatar.png');
$table->rememberToken();
$table->timestamps();
});
}
in Migrations
-------------------
<img src="{{ $page.props.auth.user.avatar }}" alt=""> {{ $page.props.auth.user.avatar }}
In my code
obs: this second {{ $page.props.auth.user.avatar }} is only for show what is coming
您需要在网站的页脚中添加类似的内容
<script>
window.user = '{{ auth()->user() }}'
</script>
然后您将能够在 vue.xml 中访问您的用户属性。 像这样:
window.user.avatar
编辑:阅读评论后; 你确定要添加吗
protected $fillable = ['name','avatar'];
protected $appends = ['avatar'];
和
public function getAvatarAttribute($value)
{
return $this->avatar = $value
}
给您的用户 model?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.