Reputation: 95
I got page 404 when I click the link
I don't know which part is wrong, can someone help me?
sidenav
<a href="{{ route('posts.indexRequest') }}">Request List</a>
route
Route::prefix('dashboard')->middleware('role:superadministrator|administrator|editor|author|contributor')->group( function () {
Route::get('/', 'PagesController@dashboard')->name('dashboard');
Route::resource('/posts', 'PostController');
Route::get('/posts/request-list', 'PostController@indexRequest')->name('posts.indexRequest');
});
Post Controller
public function indexRequest()
{
$posts = Post::where('status', 'On Request')->orderBy('created_at')->paginate(12);
return view('manages.posts.request', compact('posts'));
}
and I have the view
Upvotes: 0
Views: 55
Reputation: 35337
You cannot set a get route after a resource route if they use the same prefix.
The resource route will define posts/{post}
as the PostController@show
route, equivalent to:
Route::get('posts/{post}', 'PostController@show')
This will conflict with your bottom route and posts/request-list
and will evaluate request-list
as a post ID ({post}) in the above route.
Set all specific routes before resource routes.
Upvotes: 5