jeudi 23 janvier 2020

Authentication and guards (protect routes) in laravel

I have guard 'admin'.

how I know in Laraver guard work as multi auth(I can log in as a user and as Admin at once).

but I pretty surprise when I have an error about ERR_TOO_MANY_REDIRECTS when I log in as admin and try to check the page with auth middleware. Like admin this si no auth user no auth? Have code like this

Route::group([ 'namespace' => 'Shop','middleware' => ['auth'], 'prefix' => 'shop'], function () {
    Route::get('/', 'MainController@index')->name('shop');
    Route::get('/search', 'MainController@search')->name('shop.search');
    Route::get('/ajax-search', 'MainController@ajaxSearch')->name('shop.ajax-search');
    Route::get('autocomplete', 'MainController@autocomplete')->name('shop.autocomplete');
    Route::get('/searchbyname', 'MainController@searchbyname')->name('shop.searchbyname');


});
Route::group(['prefix' => 'cart','middleware' => ['auth:admin'], 'namespace' => 'Shop'], function () {
    Route::get('/','CartController@index')->name('shop.cart');
    Route::get('/add','CartController@add')->name('cart.add');
    Route::get('/details','CartController@details')->name('cart.details');
    Route::delete('/{id}','CartController@delete')->name('cart.delete');
});

how I can resolve this issue if I wanna that admin has all access as Authentication user + admin routes?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire