0

I'm start with Laravel 4, when i submit form, i get error: NotFoundHttpException.

routes.php

<?php // We defined a RESTful controller and all its via route directly Route::controller('feeds', 'FeedsController'); Route::get('/', array('as' => 'index', 'uses' => 'FeedsController@getIndex')); 

FeedsController.php

//The method to show the form to add a new feed public function getCreate() { //We load a view directly and return it to be served return View::make('create_feed'); } //Processing the form public function postCreate() { //Let's first run the valiadtion with all provided input $validation = Validator::make(Input::all(), Feeds::$form_rules); //If the validation passes, we add the values to the database and return to the form if($validation->passes()) { //We try to insert a new row with Eloquent $create = Feeds::create(array( 'feed' => Input::get('feed'), 'title' => Input::get('title'), 'active' => Input::get('active'), 'category' => Input::get('category') )); //We return to the form with success or error message due to state of the if($create) { return Redirect::to('feeds/create')->with('message', 'The feed added to the database successfully!'); } else { return Redirect::to('feeds/create')->withInput()->with('message', 'The feed could not be added, please try again later!'); } } else { //If the validation does not pass, we return to the form with first error message as flash data return Redirect::to('feed/create')->withInput()->with('message', $validation->errors()->first()); } } 

create_feed.blade.php

@if(Session::has('message')) <h2>{{Session::get('message')}}</h2> @endif {{Form::open(array('url' => 'feeds/create', 'method' => 'post'))}} <h3>Feed Category</h3> {{Form::select('category',array('News'=>'News','Sports'=>'Sports','Technology'=>'Technology'),Input::old('category'))}} <h3>Title</h3> {{Form::text('title',Input::old('title'))}} <h3>Feed URL</h3> {{Form::text('feed',Input::old('feed'))}} <h3>Show on Site?</h3> {{Form::select('active',array('1'=>'Yes','2'=>'No'),Input::old('active'))}} {{Form::submit('Save!',array('style'=>'margin:20px 100% 0 0'))}} {{Form::close()}} 

php artisan routes

| | GET feeds/create/{one?}/{two?}/{three?}/{four?}/{five?} | | Fe edsController@getCreate | | | | | POST feeds/create/{one?}/{two?}/{three?}/{four?}/{five?} | | Fe edsController@postCreate | | | | | GET feeds/index/{one?}/{two?}/{three?}/{four?}/{five?} | | Fe edsController@getIndex | | | | | GET feeds | | Fe edsController@getIndex | | | | | GET feeds/{_missing} | | Fe edsController@missingMethod | | | | | GET / | index | Fe edsController@getIndex | | | 

When i submit form, i get error: NotFoundHttpException and url redirect: feed/create. I don't understand.

2 Answers 2

1

Your controllers aren't restful. If you ever use artisan then you can get that to generate your controller which will generate it as restful. It will give you such methods like index(), create() store() etc. These are the restful methods you should be using.

By placing your code into each of these where you see fit then on the route you should use Route::resource('feeds', 'FeedsController').

If you ever need to generate your own methods because none of those fit into what you are doing then you should explicitly tell your route. e.g. Route::get('/', array('as' => 'index', 'uses' => 'FeedsController@getIndex'));.

Sign up to request clarification or add additional context in comments.

4 Comments

To use Artisan to create your Controller, you need to cd into your laravel directory using command or terminal. You then use php artisan controller:make ControllerName. laravel.com/docs/controllers
I was use: php artisan controller:make FeedsController to create my controller, my form: <form method="POST" action="localhost/laravel-blueprint/news/public/feeds/create" accept-charset="UTF-8">. But when submit url is: feed/create and get error.
Try using dot notation instead of forward slashes and instead of the url you could try a route or controller. {{ Form::open(array('route' => 'feeds.create')) }}
I try and get error: Route [feeds.create] not defined
0

Try changing this line

 Route::controller('feeds', 'FeedsController'); 

to

Route::resource('feeds', 'FeedsController'); 

in your routes.php

1 Comment

I was try and create_feed.blade.php no load.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.