Laravel 表单 - 路由未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26861534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:24:34  来源:igfitidea点击:

Laravel forms - route not defined

phpformsexceptionlaravelroutes

提问by Tomas Turan

I am using laravel to create simple form:

我正在使用 laravel 创建简单的表单:

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

In my routes.php file is defined route:

在我的 routes.php 文件中定义了路由:

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.

下一个异常 'ErrorException' 带有消息 'Route [postrequest] 未定义。

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

我无法在互联网上找到解决方案。我做错了什么?

采纳答案by Marcin Nabia?ek

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:

或者您当然可以使用直接 url 更改打开表单的方式:

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

But you should really consider using named routes.

但是你真的应该考虑使用命名路由

回答by Lead Developer

Open form with post method

使用 post 方法打开表单

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

Since you have written Route for post request.

由于您已经为 post 请求编写了 Route。

回答by paulalexandru

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']);