web.php
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\HomeController; use App\Http\Controllers\PostsController; use App\Http\Controllers\AboutController; use App\Http\Controllers\ContactController; use App\Http\Controllers\CategoryController; use App\Http\Controllers\TagController; use App\Http\Controllers\AdminControllers\DashboardController; use App\Http\Controllers\AdminControllers\AdminPostsController; use App\Http\Controllers\AdminControllers\AdminCategoriesController; use App\Http\Controllers\AdminControllers\TinyMCEController; /* |-------------------------------------------------------------------------- | 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('/', [HomeController::class,'index'])->name("home"); Route::get('/posts/{post:slug}',[PostsController::class,'show'])->name("posts.show"); Route::post('/posts/{post:slug}',[PostsController::class,'addComment'])->name("posts.add_comment"); Route::get('/contact', [ContactController::class , 'create'])->name("contact.create"); Route::post('/contact', [ContactController::class , 'store'])->name("contact.store"); Route::get('/about', AboutController::class)->name("about"); Route::get('/categories/{category:slug}',[CategoryController::class,'show'])->name("categories.show"); Route::get('/categories',[CategoryController::class,'index'])->name("categories.index"); /// /tags/{tag:slug} === SHOULD BE /tags/{tag:name} Route::get('/tags/{tag:name}',[TagController::class,'show'])->name("tags.show"); // Admin Dashboard //Route::get('/admin',[DashboardController::class,'index'])->name("admin.index"); Route::prefix('admin')->name('admin.')->middleware(['auth','isadmin'])->group(function(){ Route::get('/',[DashboardController::class,'index'])->name("index"); Route::post('upload_tinymce_image',[TinyMCEController::class,'upload_tinymce_image'])->name('upload_tinymce_image'); Route::resource('posts',AdminPostsController::class); Route::resource('categories',AdminCategoriesController::class); }); require __DIR__.'/auth.php';
AdminCategoriesController.php
<?php namespace App\Http\Controllers\AdminControllers; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Validation\Rule; use App\Models\Category; class AdminCategoriesController extends Controller { public function index() { return view('dashboard.categories.index'); } public function create() { return view('dashboard.categories.create'); } public function store(Request $request) { } public function show(Category $category) { return view('dashboard.categories.show', [ 'category' => $category ]); } public function edit(Category $category) { return view('dashboard.categories.edit', [ 'category' => $category ]); } public function update(Request $request, Category $category) { } public function destroy(Category $category) { } }
nav.blade.php
<!--sidebar wrapper --> <div class="sidebar-wrapper" data-simplebar="true"> <div class="sidebar-header"> <div> <img src="{{asset('assets/images/logo-icon.png')}}" class="logo-icon" alt="logo icon"> </div> <div> <h4 class="logo-text">MYBLOG</h4> </div> <div class="toggle-icon ms-auto"><i class='bx bx-arrow-to-left'></i> </div> </div> <!--navigation--> <ul class="metismenu" id="menu"> <li> <a href="" target="_blank"> <div class="parent-icon"><i class='bx bx-home-circle'></i></div> <div class="menu-title">Dashboard</div> </a> </li> <li> <a href="javascript:;" class="has-arrow"> <div class="parent-icon"><i class='bx bx-message-square-edit'></i> </div> <div class="menu-title">Posts</div> </a> <ul> <li> <a href="{{ route('admin.posts.index') }}"><i class="bx bx-right-arrow-alt"></i>All Posts</a> </li> <li> <a href="{{ route('admin.posts.create') }}"><i class="bx bx-right-arrow-alt"></i>Add New Post</a> </li> </ul> </li> <li> <a href="" class="has-arrow"> <div class="parent-icon"><i class='bx bx-menu'></i> </div> <div class="menu-title">Categories</div> </a> <ul> <li> <a href="{{ route('admin.categories.index') }}"><i class="bx bx-right-arrow-alt"></i>All Categories</a> </li> <li> <a href="{{ route('admin.categories.create') }}"><i class="bx bx-right-arrow-alt"></i>Add New Category</a> </li> </ul> </li> </ul> <!--end navigation--> </div> <!--end sidebar wrapper -->
I develop a blog and have a resource controller for posts and when I create another resource controller for categories it works fine, giving the error "Route [admin.categories.index] is not defined ". . Just I put the routes in the dashboard and if I comment the two routes for the category in the nav.blade.php file the error is raised and disappears
According to Laravel 9 documentation
Then I ran php artisan route:clear. Finally the route appeared.