Saturday, February 24, 2018

Laravel middleware different method if no access token found - development

Laravel middleware different method if no access token found

I’m newbie for Laravel passport. What I want to achieve is able to verify whether there is access token pass in by user.

I want to call @index route when there are access token found,
call @indexTest route when no access token is found.

Do I have to create custom middleware for this case?
Thanks.

In api.php

/**
 * Category
 */
Route::resource('categoriesbranches', 'CategoryCategoryBranchController@index', ['only' => ['index']])->middleware('client.credentials');
Route::resource('categoriesbranches', 'CategoryCategoryBranchController@indexTest');

In CategoryBranchController.php

    // public function __construct()
    // {
    //     $this->middleware('client.credentials')->only(['index']);
    // }

    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function index()
    {
        //different action
    }

    /**
     * Display a listing of the resource.
     *
     * @return IlluminateHttpResponse
     */
    public function indexTest()
    {
        //different action
    }


from Laravel Questions and Answers https://laravelquestions.com/laravel/laravel-middleware-different-method-if-no-access-token-found/
via Lzo Media

No comments:

Post a Comment