简体   繁体   中英

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. 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.

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

I keep on getting errors related to routing, Http or method not found exceptions. 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►

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

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 )

<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(). As for getting my form displayed I followed the same pattern except point to newProject() method in my controller.

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. I still used the same url as projects/add except pointing it to a different function in may controller named saveProject().

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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