简体   繁体   English

在Laravel 5.7中设置表单的路线

[英]Setting the Route for a Form in Laravel 5.7

I'm using Laravel, and I want to set a form, I have the following in my view. 我正在使用Laravel,我想设置一个表单,我认为以下内容。

<html>
    <body>
        <h1>Hello</h1>
        <form method="POST" action="{{ route('date_process') }}">
            <input type="text"/>
            <input type="submit" value="Enviar">
        </form>
        <script src="{{asset('js/jquery-3.3.1.min.js')}}"></script>
        <script src="{{asset('js/script.js')}}"></script>
    </body>
</html>

Routes 路线

Route::get('/', 'DateFormController@show');
Route::post('/date_process', 'DateFormController@process');

I get the following error message. 我收到以下错误消息。

Route [date_process] not defined. 路由[date_process]未定义。

How can I have set the form action to send to date_process ? 如何设置要发送到date_process的表单操作?

The route helper function will output named routes. route助手功能将输出命名的路由。 Your route is unnamed. 您的路线未命名。 You can either add a name to the route or use the url helper instead. 您可以为路由添加名称,也可以使用url帮助器。

Route::post('/date_process', 'DateFormController@process')->name('date_process');

route('date_process')

or with your current route 或您当前的路线

url('date_process')
<html>
<body>
    <h1>Hello</h1>
    <form method="POST" action="{{ route('date_process') }}">
        <input type="text"/>
        <input type="submit" value="Enviar">
    </form>
    <script src="{{asset('js/jquery-3.3.1.min.js')}}"></script>
    <script src="{{asset('js/script.js')}}"></script>
</body>
@csrf

</html>

Route::get('/', 'DateFormController@show');
Route::post('/date_process', 'DateFormController@process')->name('date_process');

or
Route::get('/', 'DateFormController@show');
Route::post('/date_process', ['uses'=>'DateFormController@process','as'=>'date_process']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM