微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有社交名流头像的 Laravel 8 Jetstream 个人资料照片

如何解决带有社交名流头像的 Laravel 8 Jetstream 个人资料照片

我正在使用 Laravel Socialite 尝试 Laravel 8 Jetstream。 问题是当我检索头像并将其 URL 用于 profile_photo_path 时。刀片文件附加了导致头像不显示的 http://localhost:8000/storage/。 screenshot here

我已启用 jetstream 的个人资料照片 config/jetstream.PHP

'features' => [
    Features::profilePhotos(),Features::accountDeletion(),],

这是我存储用户的方式 app/Http/Controllers/LoginController.PHP

    protected function registerOrLoginUser($user,$driver=null)
    {
        if(!is_null($driver)){
            $whereColumn = null;
            if($driver == 'facebook'){
                $whereColumn = "facebook_id";
            }
            if($driver == 'google'){
                $whereColumn = "google_id";
            }

            try{
                $findUser = User::where($whereColumn,$user->id)->first();
                if($findUser){
                    Auth::login($findUser);
                } else{
                    $newUser = new User();
                    $newUser->name = $user->name;
                    $newUser->email = $user->email;
                    $newUser->password = encrypt('');
                    $newUser->$whereColumn = $user->id;
                    $newUser->profile_photo_path = $user->getAvatar();
                    $newUser->save();
                    Auth::login($newUser);
                }

在这里看到了问题resources/views/navigation-menu.blade.PHP

<button class="flex text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
   <img class="h-8 w-8 rounded-full object-cover" src="{{ Auth::user()->profile_photo_url }}" alt="{{ Auth::user()->name }}" />
</button>

所以我试图修复这个刀片文件并在此处放置一个 if 语句:

<button class="flex text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out">
    <img class="h-8 w-8 rounded-full object-cover" src="{{ (Auth::user()->google_id !== null ||  Auth::user()->facebook_id !== null ) ? Auth::user()->profile_photo_path : Auth::user()->profile_photo_url }}" alt="{{ Auth::user()->name }}" />
</button>

“If 语句”有缺陷,当社交名流登录用户决定更改他们的图片时,它就会中断。我试过这个 solution 但它只将数值存储到我的 profile_photo_path。知道如何让社交名流和 Jetstream 的内置个人资料照片发挥作用吗?

解决方法

我从 [root@cent /]# curl -H "Host: myapp.com" http://10.111.197.14 { "path": "/","headers": { "host": "myapp.com","x-request-id": "ec03f71b9772921c4b07112297ee2e43","x-real-ip": "172.17.0.1","x-forwarded-for": "172.17.0.1","x-forwarded-host": "myapp.com","x-forwarded-port": "80","x-forwarded-proto": "http","x-scheme": "http","user-agent": "curl/7.29.0","accept": "*/*" },"method": "GET","body": "","fresh": false,"hostname": "myapp.com","ip": "172.17.0.1","ips": [ "172.17.0.1" 复制了 getProfilePhotoUrlAtrribute 方法 到 vendor/laravel/jetstream/src/HasProfilePhoto.php 并将其修改为接受来自社交网站的头像网址或检索上传的照片。

App\Models\User

Jetsream docs reference

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。