【发布时间】:2015-11-07 11:33:22
【问题描述】:
在 Laravel 5.1 中使用 Form:: 外观创建多维表单数组最优雅的方式是什么?
我知道我可以使用以下语法创建表单域:
{!! Form::label('work_type', 'Work Type') !!}
{!! Form::select('work_type', WorkTypes::show(), ['id' => 'work_type']) !!}
{!! Form::label('date', 'Date & Time Worked') !!}
{!! Form::text('date', date('d/m/Y'), ['id' => 'date', 'class' => 'datepicker']) !!}
{!! Form::label('overtime_start_hour', 'Overtime Start Hour') !!}
{!! Form::select('overtime_start_hour', Hours::show(), ['id' => 'overtime_start_hour']) !!}
{!! Form::label('overtime_start_minute', 'Overtime Start Minute') !!}
{!! Form::select('overtime_start_minute', Minutes::show(), ['id' => 'overtime_start_minute']) !!}
但是,我希望创建一个多维表单数组。提交表单时,我希望数组看起来像这样:
array(
[0] =>
[work_type] => 'My work type value for row 1...',
[date] => '20/03/2015',
[overtime_start_hour] => array(
[0] => 01
[1] => 03
)
[overtime_start_minute] => array(
[0] => 00
[1] => 00
)
[1] =>
[work_type] => 'My work type value for row 2...',
[date] => '21/03/2015',
[overtime_start_hour] => array(
[0] => 09
[1] => 07
)
[overtime_start_minute] => array(
[0] => 30
[1] => 00
)
)
谁能帮忙?
【问题讨论】:
-
你获取数据的变量在哪里?你能告诉我吗?
-
你能澄清一下你的意思吗?抱歉,您指的是哪个变量?我基本上想设置我的 Laravel 表单来输出一个像上面那样的数组。我只是在问我将如何创建这样的东西。
-
让你得到你想要的输出数组。你能给我在你的代码中获取的数据吗?
-
我还没有编写那部分代码,我刚刚创建表单。我还没有处理表格...
-
使用 foreach 先生 @V4n1ll4
标签: php arrays forms laravel laravel-5