Search code examples
phplaraveldingo-api

Laravel 5.2 & Dingo api.auth middleware group


I try to GET result of "testing" from the API with Authorization as header but I don't know why it doesn't work. It works for "hello" but not works for "testing". It doesn't produce any error and it redirect me to the main page of Laravel.

AuthController.php

public function show()
{
    return "testing";
}

Routes.php

$api = app('api.router');
$api->version('v1', ['middleware' => 'api.auth'], function($api){
    $api->get('show','App\Http\Controllers\Auth\AuthController@show');//not working
    $api->get('hello',function(){
        return "hello"; //works
    });
});

Solution

  • AuthController has a __construct that it use guest middleware, so if you are login in the system it will be redirect you to $redirectTo route.