Description
//Route::resource('/nwqs', NationalWaterQualityController::class); This route is not working if i add this code in below section
Route::prefix('auth')->middleware(['auth','isAdmin','isUser'])->group(function(){
Route::resource('/nwqs', NationalWaterQualityController::class);
});
I just want to access this route in both admin as well as user section.
View Code
Route::prefix('auth')->middleware(['auth','isAdmin'])->group(function(){
Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
Route::resource('/posts', PostController::class);
Route::resource('/categories', CategoryController::class);
Route::resource('/stations', StationController::class);
Route::get('/airqualities/import',[AirqualityController::class, 'import'])->name('airqualities.import');
Route::post('/airqualities/import',[AirqualityController::class, 'importSave'])->name('airqualities.importSave');
Route::resource('/airqualities', AirqualityController::class);
Route::get('/categories/download/{filename}',[CategoryController::class, 'download'])->name('categories.download');
Route::get('/categories/remove/{id}',[CategoryController::class, 'remove'])->name('categories.remove');
Route::resource('/modules', ModuleController::class);
Route::get('/modules/download/{filename}/{filetype?}',[ModuleController::class, 'download'])->name('modules.download');
Route::post('/posts/get-additional-fields', [PostController::class, 'getAdditionalFields'])->name('posts.get-additional-fields');
//Route::resource('/nwqs', NationalWaterQualityController::class);
Route::resource('/stps', StpController::class);
Route::post('/stps/checkSubRegion', [StpController::class, 'checkSubRegion'])->name('stps.checkSubRegion');
Route::post('/stps/dropdownStationCode', [StpController::class, 'dropdownStationCode'])->name('stps.dropdownStationCode');
Route::post('/stps/dropdownStationCodeAddress', [StpController::class, 'dropdownStationCodeAddress'])->name('stps.dropdownStationCodeAddress');
Route::resource('/users', UserDashboardController::class);
});
Route::prefix('auth')->middleware(['auth','isAdmin','isUser'])->group(function(){
Route::resource('/nwqs', NationalWaterQualityController::class);
});
Route::middleware(['isUser','auth'])->group(function(){
Route::get('/userdashboard', [HomeController::class, 'home'])->name('userdashboard');
Route::get('/user/profile', [UserDashboardController::class, 'profile'])->name('user.profile');
Route::post('/user/save', [UserDashboardController::class, 'save'])->name('user.save');
});
Your code looks fine but I think the prefix doesn't apply on the resource route, as you mention the prefix at the top so define it like this
~~~
Route::resource('/auth/nwqs', NationalWaterQualityController::class);
~~~
This will work for you. Let me know if you still have any issues.
0 Likes 1 Comment
Vanita saini Author
still not working. i used this code like this: Route::prefix('auth')->middleware(['auth','isAdmin'])->group(function(){ Route::resource('/nwqs', NationalWaterQualityController::class); Route::resource('/stps', StpController::class); Route::post('/stps/checkSubRegion', [StpController::class, 'checkSubRegion'])->name('stps.checkSubRegion'); Route::post('/stps/dropdownStationCode', [StpController::class, 'dropdownStationCode'])->name('stps.dropdownStationCode'); Route::post('/stps/dropdownStationCodeAddress', [StpController::class, 'dropdownStationCodeAddress'])->name('stps.dropdownStationCodeAddress'); Route::resource('/users', UserDashboardController::class); }); /*Route::middleware(['auth','isAdmin','isUser'])->group(function(){ Route::resource('/auth/nwqs', NationalWaterQualityController::class); });*/ Route::middleware(['isUser','auth'])->group(function(){ Route::get('/userdashboard', [HomeController::class, 'home'])->name('userdashboard'); Route::resource('/auth/nwqs', NationalWaterQualityController::class); Route::get('/user/profile', [UserDashboardController::class, 'profile'])->name('user.profile'); Route::post('/user/save', [UserDashboardController::class, 'save'])->name('user.save'); }); Now it works only in the user section, not for admin.
Was your problem resolved?