对null上的成员函数api()的osiset/laravel shopify错误调用

对null上的成员函数api()的osiset/laravel shopify错误调用,laravel,authentication,shopify,shopify-app,shopify-api,Laravel,Authentication,Shopify,Shopify App,Shopify Api,我已经安装了插件,并按照说明进行安装 现在,我在调用api方法时收到以下错误: Error Call to undefined method stdClass::api() 我的用户模型: use Osiset\ShopifyApp\Contracts\ShopModel as IShopModel; use Osiset\ShopifyApp\Traits\ShopModel; class User extends Authenticatable implements IShopModel

我已经安装了插件,并按照说明进行安装

现在,我在调用api方法时收到以下错误:

Error
Call to undefined method stdClass::api()
我的用户模型:

use Osiset\ShopifyApp\Contracts\ShopModel as IShopModel;
use Osiset\ShopifyApp\Traits\ShopModel;

class User extends Authenticatable implements IShopModel
{
    use Notifiable, ShopModel;
...
我的控制器:

    public function themeUpdate(ShopvoteShops $shopvoteShop, $request = null)
    {
        $user = DB::table('users')->first();
        $shopvoteShop = ShopvoteShops::where('url', $user->name)->first();
        $shop = Auth::user();

        $response = $user->api()->rest('GET', '/admin/script_tags.json');
基本上,User和Auth everytime的实例都是空的,我不能调用例如
$shop->api()
,因为
对null上的成员函数api()的错误调用。

我很高兴听到如何解决这个问题


谢谢大家!

您不需要从数据库中获取用户
osiset/laravel shopify
会在用户在商店中成功进行身份验证后,自动将商店和api信息添加到laravel身份验证
Auth::user()

查看文档:

否则,取而代之的是

$user->api()->rest('GET', '/admin/script_tags.json');
试一试

2021-04
代表API版本

更多信息可在shopify开发文档中找到:

$shop->api()->rest('GET', '/admin/api/2021-04/script_tags.json');