方法addMediaFromUrl()从spatie无法正常工作

时间:2018-05-01 12:43:30

标签: laravel spatie

我想使用spatie来获取Google+头像,但是当我尝试使用它时会出现错误。

$user = Socialite::driver('google')->user();
$usertest=User::whereEmail($user->getemail())->first();

if(! $usertest){
$usertest=User::create([
    'name'=>$user->name,
    'email'=>$user->email,
    'password'=>bcrypt($user->id)
]);}

$usertest->addMediaFromUrl($user->avatar)->toMediaCollection('avatar');
auth()->loginUsingId($usertest->id);
return redirect('/');

错误:

  

类型错误:传递给Spatie \ MediaLibrary \ FileAdder \ FileAdder :: processMediaItem()的参数1必须是Spatie \ MediaLibrary \ HasMedia \ HasMedia的实例,App \ User的实例,

1 个答案:

答案 0 :(得分:0)

您好像尚未将HasMedia界面和HasMediaTrait添加到User类:

class User extends Authenticatable implements HasMedia {

    use HasMediaTrait;

    // ...

}