在 Laravel 5.4 中创建表单的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42052285/
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 15:16:37  来源:igfitidea点击:

What is the best way to create forms in Laravel 5.4?

formslaravelblade

提问by Martin Heralecky

What is the easiest, most elegant and effective way to create forms with Blade in Laravel 5.4? I'm creating an application with many forms and most of the fields look the same:

在 Laravel 5.4 中使用 Blade 创建表单的最简单、最优雅和最有效的方法是什么?我正在创建一个具有多种表单的应用程序,并且大多数字段看起来都一样:

<label for="name">Name:</label>
<input type="text" name="name" id="name" value="{{ old('name') }}">

@if ($errors->has('name'))
<ul>
    @foreach($errors->get('name') as $error)
    <li>{{ $error }}</li>
    @endforeach
</ul>
@endif

So I wonder if there is any built-in mechanism to generate forms easily?

所以我想知道是否有任何内置机制可以轻松生成表单?

Thanks

谢谢

采纳答案by Paras

  1. You can use the Laravel Collective Forms & HTML Packagefor form model bindingand generating fields
  2. For displaying errors, you can use sub-views
  1. 您可以使用Laravel Collective Forms & HTML Package进行表单模型绑定生成字段
  2. 为了显示错误,您可以使用子视图

回答by José Neto

I would like to share my package:

我想分享我的包裹:

https://github.com/netojose/laravel-bootstrap-4-forms

https://github.com/netojose/laravel-bootstrap-4-forms

An amazing form generator based on Bootstrap 4 theming

基于 Bootstrap 4 主题的惊人表单生成器

回答by Lee

You could also use route model binding and pure HTML forms as an option.

您还可以使用路由模型绑定和纯 HTML 表单作为选项。

回答by Petraeus

php composer.phar require laravelcollective/html

php composer.phar 需要 laravelcollective/html