簡體   English   中英

如何在 Laravel 8 中設置默認頭像?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM