【发布时间】:2014-07-11 22:24:05
【问题描述】:
我有三个表 delivery-request_item、items 和一个数据透视表 delivery-request_item。在我的 create.blade.php 中,我有一个按钮,它将添加用户选择的相应数量的项目之一。
我的解决方案是将商品和数量放到 Session 中。现在我的问题是我只能创建一个记录,如果我决定添加另一个项目,前一个项目会被覆盖。
create.blade.php
{{Form::open(array('method'=>'POST','url'=>'delivery-requests'))}}
{{Form::text('requested_by', Auth::user()->email)}}
<div>
{{Form::label('Shows Items from table')}}
{{Form::select('item_id', $items)}}
{{Form::label('Quantity')}}
{{Form::text('item_quantity')}}
{{Form::submit('add item',array('name'=>'addItem'))}}
{{Form::submit('remove item', array('name' => 'removeItem'))}}
</div>
<hr>
<div>
<table>
<theader>
<tr>
<td>ITEM NAME</td>
<td>QUANTITY</td>
</tr>
</theader>
<!-- loop through all added items and display here -->
@if(Session::has('item_id'))
<h1>{{ Session::get('item_id') }}</h1>
@endif
@if(Session::has('item_quantity'))
<h1>{{ Session::get('item_quantity')}}</h1>
@endif
</table>
</div>
{{Form::submit('submit', array('name' => 'submit'))}}
{{Form::close()}}
DeliveryRequestsController@Store
if(Input::has('addItem'))
{
Session::flash('item_id', Input::get('item_id'));
Session::flash('item_quantity', Input::get('item_quantity'));
$data = Session::all();
$item = Item::lists('item_name','id');
return View::make('test')->with('data',$data)->with('items',$item);
}
【问题讨论】: