我想使用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的实例,
答案 0 :(得分:0)
您好像尚未将HasMedia
界面和HasMediaTrait
添加到User
类:
class User extends Authenticatable implements HasMedia {
use HasMediaTrait;
// ...
}