Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel forms - route not defined

I am using laravel to create simple form:

    {{ Form::open(array('route' => 'postrequest')) }}
    {{ Form::text('Name') }}
    {{ Form::text('Surname') }}         
    {{ Form::submit('submit') }}
    {{ Form::close() }}

In my routes.php file is defined route:

Route::post('postrequest', function() 
{   
    return View::make('home');
});

But I'm getting error in log file:

Next exception 'ErrorException' with message 'Route [postrequest] not defined.

I couldnt find solution on internet. What I'm doing wrong?

like image 290
Tomas Turan Avatar asked Nov 11 '14 09:11

Tomas Turan


People also ask

How to define route in web php Laravel?

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.


1 Answers

You try to use here named route. If you want to do so you need to change your route into:

Route::post('postrequest', array('as' => 'postrequest', function() 
{   
    return View::make('home');
}));

or you can of course change the way you open your form using direct url:

{{ Form::open(array('url' => 'postrequest')) }}

But you should really consider using named routes.

like image 74
Marcin Nabiałek Avatar answered Sep 23 '22 01:09

Marcin Nabiałek