Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

laravel

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 
like image 298
Delal Avatar asked Jan 20 '26 09:01

Delal


1 Answers

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
});
like image 148
Ersoy Avatar answered Jan 23 '26 01:01

Ersoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!