skip to Main Content

I have a routes folder admin.php, with following intended code

 Route::prefix('admin')->group(function(){
 Route::get('/new/dashboard',[SuperAdminController::class,'dashboard']);
 Route::get('/new/notifications', [SuperAdminController::class,'notifications']);
});

But if i go on the browser and use http://127.0.0.1:8000/admin/new/dashboard i get 404 | page not found.

But if remove the prefix and the code remains

Route::get('/new/dashboard', [SuperAdminController::class,'dashboard']); 
   Route::get('/new/notifications', [SuperAdminController::class,'notifications']);

and i go to the browser http://127.0.0.1:8000/admin/new/dashboard this route works fine and also even if i dont put prefix admin http://127.0.0.1:8000/new/dashboard its still works fine.

I have tried Checking on Routeserviceprovider tried finding any other way i might have defined it to no avail.

I have run all the debugging commands,

php artisan route:clear , php artisan config:cache, php artisan route:cache , php artisan view:cache

And the same routing works fine on the server, tried pulling and made sure all code is the same stil wont work

Here is the admin.php in summary

<?php

use IlluminateSupportFacadesRoute;

use AppHttpControllersSuperAdminSuperAdminController;
use AppHttpControllersAdminController;
use AppHttpControllersTransactionController;


Route::prefix('admin')->group(function(){
 Route::get('/new/dashboard', [SuperAdminController::class,'dashboard']);
    
    
    Route::get('/new/notifications', [SuperAdminController::class,'notifications']);




    Route::get('/new/schools/pending', [SuperAdminController::class,'schools_pending']);
    Route::get('/new/schools/pending/{id}', [SuperAdminController::class,'schools_pending_selected']);
    Route::get('/new/schools/query', [SuperAdminController::class,'schools_query']);
    Route::get('/new/schools/query/results', [SuperAdminController::class,'schools_query']);
    Route::get('/new/schools/query/results/{id}', [SuperAdminController::class,'schools_selected']);

    Route::get('/new/schools/suspended', [SuperAdminController::class,'schools_suspended']);
    Route::get('/new/schools/suspended/{id}', [SuperAdminController::class,'schools_suspended_selected']);

    Route::post('/new/schools/suspendschool', [SuperAdminController::class,'schools_suspending']);
    Route::post('/new/schools/unsuspendschool', [SuperAdminController::class,'schools_unsuspending']);
    Route::post('/new/schools/validate', [SuperAdminController::class,'schools_validate']);
 });
   

Here is web.php in summary

<?php

use AppHttpControllersFavouriteController;
use AppHttpControllersSchoolApplicationController;
use AppHttpControllersTransactionController;
use IlluminateSupportFacadesRoute;
use AppHttpControllersWebController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

/*
Route::get('/', function () {
    return view('welcome');
}); /*

/*
Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth'])->name('dashboard');
*/

require __DIR__ . '/admin.php';
require __DIR__ . '/auth.php';
require __DIR__ . '/school.php';

require __DIR__ . '/student.php';


Route::get('/changepassword/{id}/{pass}', [WebController::class, 'chpass']);



//Web Routes
Route::get('/', [WebController::class, 'landing']);

//Route::get('/dashboard', [WebController::class, 'checkoutrole']);

Route::get('/schools', [WebController::class, 'allschools']);

Route::get('/schools/level/{levelslug}', [WebController::class, 'school_by_levels']);

Route::get('/schools/{slug}', [WebController::class, 'schoolsIncategory']);

Route::get('/school/{slug}', [WebController::class, 'school_selected']);
Route::get('/school/{id}/books_rec', [WebController::class, 'book_recommended_byschool']);


Route::get('/book/{slug}', [WebController::class, 'book_selected']);
Route::get('/books', [WebController::class, 'allbooks']);

Route::get('/books/{slug}', [WebController::class, 'booksbycategory']);


2

Answers


  1. try php artisan optimize:clear
    and should you send link to github of this project because i need all code in route.php file, maybe you have problem hierarchy of routes, and check php artisan route:list

    Login or Signup to reply.
  2. 1- Define prefix and add file in RouteServiceProvider.php

        public function boot()
        {
            $this->configureRateLimiting();
    
            $this->routes(function () {
                Route::prefix('admin')
                    ->middleware('web')
                    ->namespace($this->namespace)
                    ->group(base_path('routes/admin.php'));
    
                Route::prefix('api')
                    ->middleware('api')
                    ->namespace($this->namespace)
                    ->group(base_path('routes/api.php'));
    
                Route::middleware('web')
                    ->namespace($this->namespace)
                    ->group(base_path('routes/web.php'));
            });
        }
    

    2- Remove require __DIR__ . '/admin.php'; from web.php

    3- Unwrap routes Route::prefix('admin')->group(function(){});

    4- Make sure public folder have no exact name directory like admin

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search