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

由于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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿