【问题标题】:Laravel JetStream get user avatarLaravel JetStream 获取用户头像
【发布时间】:2021-11-07 21:46:09
【问题描述】:

我确信这是因为我已经盯着这个看了几个小时,然后我错过了一些愚蠢的东西。我正在尝试提取相关用户名的头像。 :alt="user.name" 工作正常,但头像不行。

我正在使用 Laravel 和 Jetstream 来完成这项工作。我有它在其他地方工作,但不是在这里。我做错了什么?

                <td class="px-2 py-2 whitespace-nowrap">
                  <div class="flex items-center">
                    <div class="flex-shrink-0 h-10 w-10">
                      <img class="h-10 w-10 rounded-full" :src="user.profile_photo_url" :alt="user.name" />
                    </div>
                    <div class="ml-4">
                      <div class="text-sm font-medium text-gray-900 dark:text-gray-100">
                        {{ user.name }}
                      </div>
                      <div class="text-sm text-gray-500 dark:text-gray-100">
                        User Location
                      </div>
                    </div>
                  </div>
                </td>

和脚本信息

<script>
import {DotsVerticalIcon, BanIcon, AtSymbolIcon, UserAddIcon, HashtagIcon, UserCircleIcon, ExclamationIcon, ShieldCheckIcon} from '@heroicons/vue/outline';
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue';
import UserProfileSlideout from './UserProfileSlideout.vue';

export default {
    components: {
      DotsVerticalIcon,
      Menu,
      MenuButton,
      MenuItem,
      MenuItems,
      BanIcon, 
      AtSymbolIcon, 
      UserAddIcon, 
      HashtagIcon,
      UserCircleIcon,
      ExclamationIcon,
      ShieldCheckIcon,
      UserProfileSlideout,
    },
    data: function () {
        return {
          showUserProfileSlideout: false,
        }
    },
    name: 'UserListItem',
    props: ['user'],
    methods: {
      showUserProfile() {
            this.showUserProfileSlideout = !this.showUserProfileSlideout;
        },
    }
}
</script>

【问题讨论】:

  • 您是否在 Jetstream 中启用了个人资料照片?
  • 是的,我做到了。它正在其他组件中工作

标签: laravel vue.js inertiajs jetstream


【解决方案1】:

确保启用 profilePhotos

在喷射流配置中

    'features' => [
        // Features::termsAndPrivacyPolicy(),
         Features::profilePhotos(), // <-------- this
        // Features::api(),
        // Features::teams(['invitations' => true]),
        Features::accountDeletion(),
    ],

另外,请确保链接您的存储

使用这个命令:

php artisan storage:link

【讨论】:

  • 这两件事我都做过。这是代码问题而不是功能启用问题
  • 尝试更改prop的名称可能是因为已经有一个与认证用户同名的prop
猜你喜欢
  • 1970-01-01
  • 2019-10-31
  • 1970-01-01
  • 2013-01-13
  • 2018-08-19
  • 2012-07-11
  • 1970-01-01
  • 2020-11-03
  • 1970-01-01
相关资源
最近更新 更多