简体   繁体   English

Laravel NotFoundHttpException在路线上

[英]Laravel NotFoundHttpException on route

I have been struggling with something very simple here nevertheless the vagueness around Laravel's routing system that complicates its easy routing approach. 尽管如此,我一直在努力解决一些非常简单的问题,但是Laravel的路由系统的含糊之处使其复杂的路由方法变得更加复杂。 I have gone through questions listed here but nothing seems to help me so here it goes. 我已经经历了这里列出的问题,但是似乎没有任何帮助,所以就这样。

I have formerly defined a route to my controller on an action named "create". 我以前在名为“创建”的操作上定义了到控制器的路由。 This action is suppose to accept a post data from the form and persist it. 假定此操作是接受来自表单的帖子数据并将其持久化。 This create method has one parameter which defaults to null for a project id if its add else we pass an id eg domain/projects/add/22 to edit and domain/projects/add to create a new one. 这个create方法有一个参数,如果添加了其他项目,则默认为null,否则我们将传递一个id,例如domain / projects / add / 22进行编辑,而domain / projects / add则创建一个新的。

Below is the skeleton of the function: 下面是该函数的框架:

public function create( $id = null ){ ... }

I then defined a route for this which is: 然后,我为此定义了一条路线:

Route::post( 'projects/add', 'ProjectsController@create' );

Inside my form I have {{ Form::open(array('url' => 'projects/add', 'method' => 'post')) }} . 在我的表单内部,我有{{Form :: open(array('url'=>'projects / add','method'=>'post'))}}。

I keep on getting errors related to routing, Http or method not found exceptions. 我不断遇到与路由,Http或方法未找到异常相关的错误。 I tried to follow every suggestion on the net but cannot for the life of me find my way. 我试图遵循网上的所有建议,但终生找不到自己的路。

Please help me point to the right direction, thanks. 谢谢,请帮助我指出正确的方向。

try with below sample code 尝试以下示例代码

routs.php► routs.php►

Route::post('projects/add/{id?}',array('as'=>'project_create','uses'=>'ProjectsController@create'));

ProjectsController.php► ProjectsController.php►

class ProjectsController extends BaseController{

 public function create( $id = null ){
 ... 
 }  

projects.blade.php► (for used blade templating your views should have blade.php extention ) projects.blade.php► (对于用于模板化您的视图的旧刀片,应该具有blade.php扩展名)

<html>....
<form action="{{ route('project_create') }}"method="post">
    ....
</form>
</html>

Thank you guys for all your responses. 谢谢大家的答复。 After being swamped with work I finally came back to my project and wanted to try out some of your suggestions but I failed. 在工作忙碌之后,我终于回到我的项目,想要尝试您的一些建议,但是我失败了。

I did find a tutorial that I tried to follow and basically was able to have my routes working. 我确实找到了我尝试遵循的教程,并且基本上能够使我的路线正常运行。

Inside the routes I added (see below): 在我添加的路线内(见下文):

Route::get('/projects/list', [
  'as' => 'post.list', 
  'uses' => 'ProjectsController@listProjects'
]);

Inside my controller I just created a function that is named listProjects(). 在我的控制器内部,我刚刚创建了一个名为listProjects()的函数。 As for getting my form displayed I followed the same pattern except point to newProject() method in my controller. 至于显示我的表单,除了在控制器中指向newProject()方法外,我遵循相同的模式。

As much as I was not keen on this approach I ended up creating another function just for saving my POSTed form data after a new project form has been filled out and submitted. 尽管我并不热衷于这种方法,但最终我还是创建了另一个函数,该函数仅用于在填写并提交新项目表单后保存POST表单数据。 I still used the same url as projects/add except pointing it to a different function in may controller named saveProject(). 我仍然使用与project / add相同的url,只是将其指向名为saveProject()的may控制器中的另一个函数。

About the view I just added the as part of the same save route and it worked. 关于视图,我只是在同一保存路线中添加,它起作用了。 below is a link to the tutorial I followed and taking a look at the code. 下面是我遵循的教程的链接,并看了一下代码。

http://www.codeheaps.com/php-programming/creating-blog-using-laravel-4-part-1/ http://www.codeheaps.com/php-programming/creating-blog-using-laravel-4-part-1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM