Laravel forms - route not defined
17,362
Solution 1
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.
Solution 2
Open form with post method
{{ Form::open(array('url' => 'postrequest', 'method' => 'post')) }}
Since you have written Route for post request.
Solution 3
In case you want to reference a controller method in you route, you have to do something like this:
Route::post('postrequest', ['as' => 'postrequest', 'uses' => 'RequestController@store']);
Author by
Tomas Turan
Updated on July 04, 2022Comments
-
Tomas Turan almost 2 years
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?
-
Tomas Turan over 9 yearsmethod is implicitly set to 'post'.
-
Marcin Nabiałek over 9 yearsBecause in your code, you created route with exact url (without name), and if you use in form
route
, it means you want to use route with name you given. So Laravel was looking for route with namepostrequest
but it didn't find any because you didn't give any name for your route. -
Tomas Turan over 9 yearsAnd if I use ('url' => 'postrequest') framework will use the url of route defined in routes.php?
-
Marcin Nabiałek over 9 yearsYes, it will finally use the route defined in routes.php but when you decide to change the url you will need to change them in rotues and in form and when using named routes you will change url only and routes and leave name without change
-
Jason about 9 yearsNice. I was trying to use "method" to pass a URL into Form::open, and it was treating the method as a route instead of a URL. Passing the url in via the "url" element instead is the fix that worked for me, albeit a slightly different issue. Thanks.