DIPAK KUMAR SINGH
DIPAK KUMAR SINGH

Reputation: 113

Skipping a middleware for a particular route inside a route group in Laravel

I Want to skip the middleware for a particular route in a route group. How can I do this?

Route::group(['prefix' => 'testgroup','middleware' => ['login.oauth']],function (){
    Route :: get('/', 'testController@index');
    Route :: get('/api','testController@apiCall');
}); 

I want to skip the 'login.oauth' middleware for the Route :: get('/api','testController@apiCall')

Upvotes: 3

Views: 519

Answers (2)

Soniya Basireddy
Soniya Basireddy

Reputation: 369

Please keep that testgroup function must be accessible to all routes and middleware function to particular(some other route) in the same function

    Route::group(['prefix' => 'testgroup'], function () {
       Route::group(['middleware' => ['login.oauth'], function() {
        Route :: get('/', 'testController@index');
       });
       Route :: get('/api','testController@apiCall');
    });

Upvotes: 2

Andrew
Andrew

Reputation: 1150

Just create a second group without the middleware:

Route::group(['prefix' => 'testgroup','middleware' => ['login.oauth']],function (){
    Route :: get('/', 'testController@index');
});

Route::group(['prefix' => 'testgroup'],function (){
    Route :: get('/api','testController@apiCall');
});

Upvotes: 1

Related Questions