0

I use laravel4 form my application in which users can store some data with post form to database. When i post blank form i got error NotFoundHttpException. I have in HomeController

public function create()
{
    $validation = Producer::validate(Input::all());

    if ($validation->fails()) {
        return Redirect::to('home/create')->withErrors($validation->errors());
    } else {




        $producer = new Producer;
        $producer->title = Input::get('title');
        $producer->body = Input::get('body');
        $producer->url = Input::get('url');

        $producer->save();

        return Redirect::to('/');
    }
}

model

class Producer extends Eloquent {

public static $rules = array(
    'title'=>'required|min:5',
    'body'=>'required|min:10',
    'url' => 'required'
);

public static function validate($data) {
    return Validator::make($data, static::$rules);
}

and view

@if($errors->has())
   <ul>
     {{ $errors->first('title', '<li>:message</li>') }}
     {{ $errors->first('body', '<li>:message</li>') }}
     {{ $errors->first('url', '<li>:message</li>') }}
   </ul>
@endif
   {{ Form::open(array('url' => 'create')) }}
     <p>{{ Form::label('title', 'Název služby') }}</p>
     <p>{{ Form::text('title') }}</p>
     <p>{{ Form::label('body', 'Popis') }}</p>
     <p>{{ Form::textarea('body') }}</p>
     <p>{{ Form::label('url', 'Adresa webu') }}</p>
     <p>{{ Form::textarea('url') }}</p>
     <p>{{ Form::submit('Přidat',array('class' => 'btn btn-default')) }}</p>
   {{ Form::close() }}

but when i run this script i obtain error NotFoundHttpException. Where is a problim in my code in route?

my routes

Route::get('/', 'HomeController@showWelcome');

Route::get('/detail/{id}', 'HomeController@detail');

Route::get('/add', 'HomeController@add');

Route::post('/create', 'HomeController@create');

now i have

Route::get('/', 'HomeController@showWelcome');

Route::get('/detail/{id}', 'HomeController@detail');

Route::get('/add', 'HomeController@add');

Route::post('/create', 'HomeController@create');

Route::get('/create', 'HomeController@create');

and

if ($validation->fails()) {
  return Redirect::to('/create')->withErrors($validation);
} else {

an still same problem

solved i have big mistake i redirect to bad rout i need to use HomeController@add because this make View for the form

1
  • Can you post the relevant routes from routes.php Commented Oct 10, 2013 at 10:57

1 Answer 1

1

The route home/create doesn't exist. Check your routes, it should be /create. Another problem, you need a route for create that handles get. At the moment you only have one for post.

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

1 Comment

If I just pass validator that produce the same error I think the problem is in my route

Your Answer

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.