Delal
Delal

Reputation: 107

BadMethodCallException: Method Illuminate\Routing\Route::withoutMiddleware does not exist

Does anyone have any idea about this exception?

Route::group(['middleware' => 'auth:api'], function() {

//Blog routes
Route::get('blog', 'ApiControllers\ApiBlogController@index')->name('blog.index')->withoutMiddleware('auth:api');
//User routes
Route::get('user', 'ApiControllers\ApiUserController@index')->name('user.index');
Route::delete('user/{user}', 'ApiControllers\ApiUserController@destroy')->name('user.destroy');
Route::get('user/{user}', 'ApiControllers\ApiUserController@show')->name('user.show');
Route::put('user/{user}', 'ApiControllers\ApiUserController@update')->name('user.update');
});

Exception

BadMethodCallException: Method Illuminate\Routing\Route::withoutMiddleware does not exist. in file 

Upvotes: 3

Views: 2530

Answers (1)

Ersoy
Ersoy

Reputation: 9594

WithoutMiddleware is a trait used in testing. Also there is a method named withoutMiddleware in this trait used for testing.

If you want to exclude a route from middleware you may remove blog-routes from route group of auth:api middleware such as

Route::get('blog', 'ApiControllers\ApiBlogController@index')->name('blog.index');

Route::group(['middleware' => 'auth:api'], function() {
    // other routes
});

Upvotes: 1

Related Questions