Reputation: 9
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;
}
Upvotes: 0
Views: 2031
Reputation: 51
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.php
also 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;
Upvotes: 1