Auth Guard [api] 未定义

问题描述 投票:0回答:2

我检查了几个问题,都出现了我上面提到的相同错误。但找不到答案。 我正在尝试将我的 Base64 字符串转换为图像文件。 这是我的控制器中的代码,

public function createImage(Request $request)
    {
      $user = auth('api')->user();
      if($request->photo){
         $name = time().'.'. explode('/', explode(':', substr($request->photo, 0, strpos
         ($request->photo, ';')))[1])[1];
         \Image::make($request->photo)->save(public_path('public/').$name);
        }
    }

通过 Postman 使用 Base64 编码字符串执行此操作时,出现以下错误:

"message": "Auth guard [api] is not defined.",
    "exception": "InvalidArgumentException",
    "file": "C:\\xampp\\htdocs\\konekt\\testmyusers-api\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\AuthManager.php",

我不知道我的控制器代码是否正确。我使用 YouTube 视频作为来源。我可以这样做还是应该改变我的方法?

laravel authentication base64 intervention
2个回答
2
投票

我认为你没有在

api
中添加守卫
config/auth.php
。 如果未添加,请在
config/auth.php
中添加以下防护以及司机和提供商详细信息。

'guards' => [
        'api' => [
            'driver' => 'passport',
            'provider' => 'user',
        ],
    ]

0
投票

我的团队在使用 Passport API 库时遇到了很多类似的问题,因此,如果您正在使用它,并且不需要 Passport 的 OAuth 复杂程度,我建议您研究一下 Sanctum

© www.soinside.com 2019 - 2024. All rights reserved.