0

I'm building an API for a webapp I made to train myself in Laravel. I integrated a token based authentication system by Tappleby, like this:

Route::get('api/v1/auth', 'Tappleby\AuthToken\AuthTokenController@index');

Route::post('api/v1/auth', 'Tappleby\AuthToken\AuthTokenController@store');

Route::delete('api/v1/auth', 'Tappleby\AuthToken\AuthTokenController@destroy');

Route::group(['prefix' => 'api/v1', 'before' => 'auth.token'], function ()
{

    Route::resource('user', 'ApiUsersController');

});

In ApiUsersController I, ideally, want to do something like this:

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 $user;

}

However, header() is not available for the controller. How can I solve this?

1 Answer 1

2

In Laravel, you can retrieve the HTTP headers like so:

$value = Request::header('Content-Type');

Add this to your controller and you can then do what you need to with it.

Also, you can change Content-Type to whatever it should be.

Read more here: http://laravel.com/docs/4.2/requests

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.