Laravel 4 一个表格,用于通过laravel中的mass asignment进行编辑和更新
我必须使用一种常用的表单来创建和更新laravel中的数据,使用mass赋值。我使用了以下代码 为了创造Laravel 4 一个表格,用于通过laravel中的mass asignment进行编辑和更新,laravel-4,Laravel 4,我必须使用一种常用的表单来创建和更新laravel中的数据,使用mass赋值。我使用了以下代码 为了创造 public function create() { $this->layout->content = View::make('suppliers.create')->with('action', 'storesupplier')->with('method', 'POST'); } 更新 public function update(
public function create() {
$this->layout->content = View::make('suppliers.create')->with('action', 'storesupplier')->with('method', 'POST');
}
更新
public function update() {
$this->layout->content = View::make('suppliers.edit')->with('user', Supplier::find($id))->with('action', 'updatesupplier')->with('method', 'POST');;
}
我提出了如下的观点
{{Form::open(array('route' => $action, 'class' => 'form-horizontal locations'))}}
<p> Supplier Code</p>
{{Form::text('SupplierCode', '', array('class' => 'form-control'))}}
{{$errors->first('SupplierCode')}}
<p>Supplier Name </p>
{{Form::textarea('SupplierName', '', array('class' => 'form-control', 'cols' => '2', 'rows' => '1'))}}
{{$errors->first('SupplierName')}}
{{Form::close()}}
{{Form::open(数组('route'=>$action,'class'=>'表单水平位置'))}
供应商代码
{{Form::text('SupplierCode','',数组('class'=>'Form control'))}
{{$errors->first('SupplierCode')}
供应商名称
{Form::textarea('SupplierName','',array('class'=>'表单控件','cols'=>'2','rows'=>'1'))}
{{$errors->first('SupplierName')}
{{Form::close()}}
我认为我做得最正确,但当用于更新时,我不知道如何替换input::old('supplierCode') 您可以使用
Form::model()
,它为您完成加载数据的所有工作:
@if($action == 'storesupplier')
{{Form::open(array('route' => $action, 'class' => 'form-horizontal locations'))}}
@else
{{Form::model($user, array('route' => $action, 'class' => 'form-horizontal locations'))}}
@endif
<p> Supplier Code</p>
{{Form::text('SupplierCode', '', array('class' => 'form-control'))}}
{{$errors->first('SupplierCode')}}
<p>Supplier Name </p>
{{Form::textarea('SupplierName', '', array('class' => 'form-control', 'cols' => '2', 'rows' => '1'))}}
{{$errors->first('SupplierName')}}
{{Form::close()}}
@if($action=='storesupplier')
{{Form::open(数组('route'=>$action,'class'=>'Form horizontal locations'))}
@否则
{{Form::model($user,array('route'=>$action,'class'=>'Form horizontal locations'))}
@恩迪夫
供应商代码
{{Form::text('SupplierCode','',数组('class'=>'Form control'))}
{{$errors->first('SupplierCode')}
供应商名称
{Form::textarea('SupplierName','',array('class'=>'表单控件','cols'=>'2','rows'=>'1'))}
{{$errors->first('SupplierName')}
{{Form::close()}}
注意:这是一个快速、肮脏且未经测试的解决方案,只是为了向您展示它是多么容易