Home > Mobile >  LARAVEL 9 Route [posts.all] not defined error
LARAVEL 9 Route [posts.all] not defined error

Time:07-14

For some reason Laravel says the route 'posts.all' is not defined. here's my code:

html:

<li>
   <a href="{{route('posts.all')}}" >
      <i ></i>
         <span>All Posts</span>
   </a>
</li>

Laravel Controller group with middleware:

Route::middleware(['auth'])->name('dashboard')->group(function(){
    Route::controller(\App\Http\Controllers\PostController::class)->group(function(){
        Route::get('/dashboard', 'Dashboard')->name('dashboard');
        Route::get('/posts/all', 'AllPosts')->name('posts.all');
    });
});;

however, when i refactor the code to this, it works, but i want to keep in in the PostController

Route::get('/posts/all', [\App\Http\Controllers\PostController::class, 'AllPosts'])->name('posts.all');

CodePudding user response:

you are grouping everything with the dashboard name.

->name('dashboard')->group(function(){});

So your route name ends up being dashboardposts.all, this can be debugged with php artisan route:list.

Assuming you want this structure, i would add a dash between dashboard and posts name, by calling the first name group.

->name('dashboard.')

Then access it like so.

route('dashboard.posts.all')
  • Related