【问题标题】:Laravel - The page you are looking for could not be foundLaravel - 找不到您要查找的页面
【发布时间】:2018-10-21 15:11:02
【问题描述】:

当我点击链接时,我得到了 404 页

我不知道哪一部分错了,谁能帮帮我?

sidenav

<a href="{{ route('posts.indexRequest') }}">Request List</a>

路线

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');
});

后控制器

public function indexRequest()
{
  $posts = Post::where('status', 'On Request')->orderBy('created_at')->paginate(12);

  return view('manages.posts.request', compact('posts'));
}

我有意见

【问题讨论】:

    标签: php laravel http-status-code-404


    【解决方案1】:

    如果资源路由使用相同的前缀,则不能在资源路由之后设置获取路由。

    资源路由将posts/{post}定义为PostController@show路由,相当于:

    Route::get('posts/{post}', 'PostController@show')
    

    这将与您的底部路由和 posts/request-list 冲突,并将 request-list 评估为上述路由中的帖子 ID ({post})。

    在资源路由之前设置所有特定路由。

    【讨论】:

    • 谢谢,我之前不知道
    【解决方案2】:

    您是否尝试直接访问您的“app-link/posts/request-list”

    【讨论】:

    • @SilentK1D,避免发布澄清问题的答案。一旦你在这里有了声望,你就可以在 cmets 中问这些问题,但这不是答案。
    猜你喜欢
    • 2015-11-22
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 2018-04-22
    • 2023-03-23
    相关资源
    最近更新 更多