不明白为什么我一直收到这个错误:SymfonyComponentHttpKernelExceptionN


Do not understand why I keep getting this error: Symfony Component HttpKernel Exception NotFoundHttpException

我知道这是一个路由错误,但我在路由中找不到任何错误。

  // comments
  Route::get('/comments', 'CommentsController@index');

这是控制器。

 /**
 * Display a listing of the resource.
 * GET /comments
 *
 * @return Response
 */
public function index()
{
    return View::make('comments.create');
}

提前谢谢。对某人来说,这可能是一个容易的15分。

我认为当您尝试提交表单时会出现问题

Route::get('/comments', 'CommentsController@index');

它只适用于GET请求,如果你尝试提交你的表格,你可能会使用POST方法

你可以添加到你的路线:

Route::post('/comments', 'CommentsController@index');

如果你想在控制器中路由到相同的方法,或者创建另一个方法并路由到它。

您也可以使用:

Route::any('/comments', 'CommentsController@index');

如果您不关心方法,那么所有请求(包括POST和GET)都将定向到路由。

考虑到显示了完整的routes.php文件,您需要在顶部添加PHP左括号:

<?php
// comments
Route::get('/comments', 'CommentsController@index');

忽略这一点会给你带来错误。

我能想到两件事。第一条是您的路线:

Route::get('/comments', 'CommentsController@index');

我认为可能是:

Route::get('comments', 'CommentsController@index'); // Note the omitted /
Route::get('comments', array('as' => 'comments', 'uses' => 'CommentsController@index');

理论上,这应该可以解决问题,但如果不能,我在使用视图时还有一件不同的事情。您有:

return View::make('comments.create');

我使用:

return View::make('comments/create');

文件夹结构的位置:

views->comments->create.blade.php

现在我不知道这会不会/如何影响它,试试看。

看起来您在这个路由上有一个auth过滤器。如果您的AuthController没有设置,或者缺少login方法,当filter.php中的auth筛选器尝试重定向到您的登录页面时,您将获得NotFoundHttpException