Indra Sukmajaya
Indra Sukmajaya

Reputation: 95

Laravel - The page you are looking for could not be found

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

Folder Structure

Upvotes: 0

Views: 55

Answers (2)

Devon Bessemer
Devon Bessemer

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

SilentK1D
SilentK1D

Reputation: 5

did you try to direct access to your "app-link/posts/request-list"

Upvotes: 0

Related Questions