douzhang7603 2014-10-06 20:43
浏览 987
已采纳

由于Vendor文件夹找不到Laravel类?

I'm currently implementing a token based authentication system in my API. This was build by Tappleby and it's installed in the Vendor folder of my Laravel installation. This works great as a filter. However, I need some functions of the package in my controller. I added use Tappleby\AuthToken\AuthToken; to the controller and added the necessary lines to __construct. That doesn't work though, because I keep getting Class AuthTokenDriver does not exist.

Is that because the file is in the Vendor folder? Below you can see the controller, but please not that Tappleby\AuthToken\Exceptions\NotAuthorizedException is located in the Vendor folder.

use Illuminate\Events\Dispatcher;

use Tappleby\AuthToken\Exceptions\NotAuthorizedException;

class ApiUsersController extends ApiController {

    /**
    * @var Acme\Transformers\UserTransformer
    */

    protected $UserTransformer; 

    /**
    * The event dispatcher instance.
    *
    * @var \Illuminate\Events\Dispatcher
    */
    protected $events;

    /**
    * @var \Tappleby\AuthToken\AuthTokenDriver
    */
    protected $driver;

    function __construct(UserTransformer $userTransformer, UserLessonsTransformer $userLessonssTransformer, AuthTokenDriver $driver, Dispatcher $events)
    {

        $this->UserTransformer = $userTransformer;

        $this->UserLessonTransformer = $userLessonTransformer;

        $this->driver = $driver;

        $this->events = $events;

    }

    public function index() 
    {

        $payload = Request::header('X-Auth-Token');

        if(empty($payload)) {

            return $this->respondNotFound('User does not exist.');

        }

        $user = $this->driver->validate($payload);

        return $payload;

    }
  • 写回答

1条回答 默认 最新

  • douyong7199 2014-10-06 21:06
    关注

    The Vendor folder is what Composer uses for maintaining your packages for you. So if another server or someone else wanted to check your project out, rather than porting over all those powerful packages Laravel uses and extras, they can download themselves via Composer.

    However in this case you will need to look into the documentation for this package and make sure you've followed all the instructions like including the ServiceProvider in your app/config/app.phpalso stated on the readme: -

    https://github.com/tappleby/laravel-auth-token

    I'm not quite 100% clear on this particular package but remember to dump your autoloader after : -

    composer dump-autoload
    

    Finally to allow the controller to use it in this class, try this with your other dependencies listed: -

    use \Tappleby\AuthToken\AuthTokenDriver;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀