嗨,我正在使用laravel表单。
{!! Form::text('product_name', null, array('class' => 'form-control date_pick')) !!}
是否可以通过控制器设置此默认输入?认为我们可以使用Flash做到这一点,但我找不到示例。我想从模型中提取线索并进行预填充。
$products = Products::all();
如果有人知道该怎么做,那会很棒。最简单的方法是什么?
这是通过基本的编辑路径来完成的,您只需使用以下路径:
在ModelController中,您将调用编辑页面:
public function edit(ModelName $model) {
return view('name.of.the.blade.view', compact('model')); // if using compact then without dollar symbol
}
在刀片视图中,只需使用该模型的所有输入字段创建表单:
{!! Form::model($model, ['method' => 'PATCH', 'route' => ['model.update', $model->id],]) !!}
Now all the form fields will have the values from that model.
{!! Form::close() !!}
以及编辑和更新路由(在routes / web.php内部)是这样的:
Route::get('/model/{model}/edit', 'ModelController@edit')->name('model.edit');
Route::patch('/model/{model}', 'ModelController@update')->name('model.update');