我的form.blade.php
是这样的
<div class="form-group">
{!! Form::label('title', 'title :', ['class' => 'awesome']) !!}
{!! Form::text('product[title]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('description', 'description : ', ['class' => 'awesome']) !!}
{!! Form::text('product[description]', null, ['class' => 'form-control']) !!}
<div id="phone" class="form-group">
{!! Form::label('reference_id1', 'reference_id1 : ', ['class' => 'awesome']) !!}
{!! Form::text('product[reference_id1]', null, ['class' => 'form- control']) !!}
</div>
<div class="form-group">
{!! Form::label('category_id', 'category_id : ', ['class' => 'awesome']) !!}
{!! Form::select('category[]', $categories,null, ['class' => 'form- control', 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label('color', 'color : ', ['class' => 'awesome']) !!}
{!! Form::text('feature[0][color]', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('height', 'height : ', ['class' => 'awesome']) !!}
{!! Form::text('feature[0][height]', null, ['class' => 'form-control']) !!}
</div> `
我的Edit.blade.php
是
{!! Form::model($product,['method' => 'PATCH', 'action' => ['ProductController@update',$product->id]]) !!}
@include('products.form', ['submitBtn' => 'submit'])
{!! Form::close() !!}
这是我的ProductController.php@edit
public function edit($id)
{
$product = Product::with('feature')->findOrFail($id);
$categories = Category::pluck('title','id');
return view('products.edit')->withProduct($product)->withCategories($categories);
}
这是当我想编辑一个产品时,输入请求被设置为空!!例如,当我去http://myLarave/Public/product/2/edit的title
和其他输入是空的:(有什么建议吗? !
在route.php或web.php中(取决于您的应用程序的版本),您可以设置参数{id?}
,例如:
Route::get('edit/{id?}', 'ProductController@edit');
,在编辑函数中,您可以初始化变量$id=null或空:
public function edit($id = null)
{
if($id != null){
$product = Product::with('feature')->findOrFail($id);
$categories = Category::pluck('title','id');
return view('products.edit')->withProduct($product)->withCategories($categories);
}
}