我的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
时,其他输入为空:(
有什么建议吗?!
答案 0 :(得分:0)
在您的route.php或web.php中依赖于您的laravel的版本,您可以制作arg {id?}
,例如:
Route::get('edit/{id?}', 'ProductController@edit');
在编辑功能中,您可以初始化变量$ id = null或empty:
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);
}
}