GuardHelpers无法使用customGuard

时间:2016-02-24 23:18:16

标签: php laravel lumen lumen-5.2

我做了以下定制警卫:

<?php
namespace App\Auth;

use Illuminate\Http\Request;
use Illuminate\Auth\GuardHelpers;
use Illuminate\Contracts\Auth\Guard;

class LicenseGuard implements Guard
{
    use GuardHelpers;

    protected $request;

    public function __construct(LicenseUserProvider $provider, Request $request)
    {
        $this->provider = $provider;
        $this->request  = $request;
    }

    public function user ()
    {
        // If we've already retrieved the user for the current request we can just
        // return it back immediately. We do not want to fetch the user data on
        // every call to this method because that would be tremendously slow.
        if (!is_null($this->user))
            return $this->user;

        $user       = null;
        $licenseKey = $this->request->json('license_key');

        if (!empty($licenseKey)) {
            $user = $this->provider->retrieveByLicense($licenseKey);
        }

        return $this->user = $user;
    }

    public function validate (Array $credentials = [])
    {
       /* Validate code */
    }
}
?>

在我的中间件中,我定义了以下内容:

<?php
if($this->auth->guard($guard)->quest())
    return response('You have entered an unknown license key', 401);

我得到的错误是:
致命错误:调用未定义的方法App \ Auth \ LicenseGuard :: quest()

我正在使用具有“任务”方法的默认GuardHelper特征,我只是无法找出发生这种情况的原因。

我正在使用PHP7和Lumen 5.2

1 个答案:

答案 0 :(得分:1)

不确定你在那里做我的朋友,但我认为quest“不是你正在寻找的机器人。”