B nM
B nM

Reputation: 409

laravel route for index page doesnt work but the route exists

I've got the really bad error, I have a folder named "replies" in this directory "views/admin/comments/replies". and controller name "CommentRepliesController". the routes are defined like below:

Route::group(['middleware'=>'admin'], function(){
Route::resource('admin/users', 'AdminUsersController');
Route::resource('admin/posts', 'AdminPostsController');
Route::resource('admin/categories', 'AdminCategoriesController');
Route::resource('admin/photos','AdminPhotosController');

Route::resource('admin/comments', 'PostsCommentsController');

Route::resource('admin/comments/replies', 'CommentRepliesController');
Route::get('/admin', function (){
  return view('admin.index');
 });
 });

all my routes work fine except for replies when I try to go "mysite.com/admin/comments/replies, I get 404 page. when I change the directory to "views/admin/replies" and route to Route::resource('admin/replies', 'CommentRepliesController'); the index link work perfectly. my this route on my list is like below:

| GET|HEAD | admin/comments/replies | replies.index | 
App\Http\Controllers\CommentRepliesController@index | web,admin |

please help me understand this. best regards

Upvotes: 0

Views: 620

Answers (1)

Don't Panic
Don't Panic

Reputation: 14510

Your resource('admin/comments') routes are conflicting with the following resource('admin/comments/replies') routes.

One of the routes created for admin/comments will be for admin/comments/{comment} - that is the standard show route.

Now consider a request to admin/comments/replies. The first route in your route file which matches that is the show route for comments above - the {comment} wildcard matches replies.

The order of the routes is important, so if you move your admin/comments/replies route above the admin/comments route, it should work. Alternatively (and more simply), you should not "nest" resource routes like this, and use different prefixes.

Upvotes: 1

Related Questions