3

I have a problem with my form in laravel, So my project structure is:

controllers/
 administration/
 NewsController.php

in NewsController I have a method call : postCreate():

 public function postCreate(){
 $validator = Validator::make(Input::all(), \News::$rules);
 if($validator->passes()){
 $news = new \News();
 $news->title = Input::get('title');
 $news->content = Input::get('content');
 $news->author = Input::get('author');
 $news->type = Input::get('type');
 $image = Input::file('file');
 $filename = time().".".$image->getClientOriginalExtension();
 $path = public_path('content/images/' . $filename);
 Image::make($image->getRealPath())->resize(468,249)->save($path);
 $news->image = 'content/images/'.$filename;
 $news->save();
 return Redirect::to('/administration/news/add')
 ->with('message','Succes');
 }
 return Redirect::to('/administration/news/add')
 ->with('message','Error')
 ->withErrors($validator)
 ->withInput();
}

My form have action :

{{ Form::open(array('url'=>'administration/news/create', 'files'=>true)) }}
{{ Form::close() }}

My route:

Route::post('/administration/news/create', array('uses'=>'App\Controllers\Administration \NewsController@postCreate'));

But when I submit I get an error:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

I don't understand where is my problem.

asked Nov 12, 2014 at 12:32
3
  • run php artisan routes to see if each of the routes have been declared properly. Commented Nov 12, 2014 at 12:37
  • It's better to send a form to an action. That way Laravel will automaticaly set the form to post or get. Commented Nov 12, 2014 at 12:41
  • what namespace you are using? Commented Nov 12, 2014 at 12:52

2 Answers 2

1

A small adjustment.... forget manually creating addresses.

In routes.php:

Route::post('/administration/news/create', 
 array('uses'=>'App\Controllers\Administration\NewsController@postCreate',
 'as' => 'news.post.create'));

In View:

{{ Form::open(array('url'=>route('news.post.create'), 'files'=>true)) }}

no need to memorise any of those addresses.

answered Nov 12, 2014 at 12:55
Sign up to request clarification or add additional context in comments.

Comments

1

You have a whitespace in your code. Your route should be:

Route::post('/administration/news/create', array('uses'=>'App\Controllers\Administration\NewsController@postCreate'));

Besides that, altough laravel gives you standard a POST action, its always better to add a POST action to your form.

'method' => 'post'
answered Nov 12, 2014 at 12:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.