问题
I know this is a routing error but I can't find any errors in my routes.
// comments
Route::get('/comments', 'CommentsController@index');
This is the controller.
/**
* Display a listing of the resource.
* GET /comments
*
* @return Response
*/
public function index()
{
return View::make('comments.create');
}
Thank you in advance. It is probably an easy 15 points to someone.
回答1:
I think the problem occurs when you try to submit your form. When you use:
Route::get('/comments', 'CommentsController@index');
it's only for GET
request and if you try submit your form probably you use POST
method
You could add to your routes:
Route::post('/comments', 'CommentsController@index');
if you want to route to the same method in your controller or create another method and route to it.
You can also use:
Route::any('/comments', 'CommentsController@index');
if you don't care about method - all requests (including POST and GET) would be directed to the route.
回答2:
Given the fact that the full routes.php
file is shown, you need to add the PHP opening brackets at the top:
<?php
// comments
Route::get('/comments', 'CommentsController@index');
Omitting that will give you exactly the error you're getting.
回答3:
There's two things I can think of. The first is yours route:
Route::get('/comments', 'CommentsController@index');
I think it could be either:
Route::get('comments', 'CommentsController@index'); // Note the omitted /
Route::get('comments', array('as' => 'comments', 'uses' => 'CommentsController@index');
In theory, that should fix the issue, but if not, there's one more thing I do differently when using views. You have:
return View::make('comments.create');
I use:
return View::make('comments/create');
Where the folder structure would be:
views->comments->create.blade.php
Now I have no idea if/how that would affect it, give those a try.
回答4:
It looks like you have an auth
filter on this route. If your AuthController
is not set up, or is missing the login
method, you will get a NotFoundHttpException
when the auth
filter in filter.php
tries to redirect to your login page.
来源:https://stackoverflow.com/questions/25892238/do-not-understand-why-i-keep-getting-this-error-symfony-component-httpkerne