-1

i have route api code like this

Route::group(['middleware' => 'auth:api','web'], function(){
    Route::get('user', 'Api\AuthController@user');
    Route::get('kurir', 'Api\AuthController@kurir');
    Route::get('droppoint', 'Api\DroppointController@index');
    Route::get('droppoint/{id}', 'Api\DroppointController@show');
    Route::post('droppoint', 'Api\DroppointController@store');
    Route::put('droppoint/{id}', 'Api\DroppointController@update');
    Route::delete('droppoint/{id}', 'Api\DroppointController@destroy');
});

Route::group(['middleware' => 'auth:kurirs-api','web'], function(){
    Route::get('user', 'Api\AuthController@user');
    Route::get('kurir', 'Api\AuthController@kurir');
    Route::get('droppoint', 'Api\DroppointController@index');
    Route::get('droppoint/{id}', 'Api\DroppointController@show');
    Route::post('droppoint', 'Api\DroppointController@store');
    Route::put('droppoint/{id}', 'Api\DroppointController@update');
    Route::delete('droppoint/{id}', 'Api\DroppointController@destroy');
});

I want to make login program with two role "user" and "kurir".

My question is why its just authorized the last one "kurirs-api", and if i access the first one its show unauthenticated? and if i change the position, it's only authorized "auth:api". What to do to make the code can authorize "api" and "kurirs-api"?

I have searching in the internet but the problem still doesnt solve

Henry
  • 11
  • 2

2 Answers2

3

if you want to have multiple middlewares, you have to make it an array:

// like this
Route::group(['middleware' => ['auth:kurirs-api','web']], function() {
    //
});

Amjad
  • 344
  • 1
  • 8
-1

if you want to have multiple middlewares you need to use array

Route::group(['middleware' => ['auth', 'web']], function() {
  //your route here 
});
eglease
  • 2,445
  • 11
  • 18
  • 28