【发布时间】:2017-04-09 18:10:37
【问题描述】:
我最近一直在 laravel 中开发一个 webapp,我想在应用程序中拥有一个 eddit 功能。但我收到此错误缺少 [Route: producten.update] [URI: producten/{producten}] 所需的参数,我不知道我做错了什么。
这是我正在使用的路线:
Route::resource('producten', 'ProductenController', ['only' => ['index', 'store', 'update', 'delete', 'edit', 'destroy', 'create']]);
这是我用来显示编辑页面和更新的控制器功能。
编辑功能
public function edit(Request $request, Product $product)
{
// $product = Product::FindorFail($id);
// Product is a table with all products, with sellprice and buy price
// fabriek = table that has a foreign key attached to the product table
return view('producten.edit', [
'model' => $product,
'fabrieks' => Fabriek::lists('Id')
]);
}
更新函数:
public function update(Request $request, Product $product)
{
$product->update($request->all());
return redirect(Route('producten.index'));
}
这是我使用的视图。
{{Form::model($model, ['method' => 'PATCH', 'action' => 'ProductenController@update', $model ]) }}
{{ Form::label('naam:')}}
{{ Form::text('naam') }} <br>
{{ Form::label('inkoopPrijs:')}}
{{ Form::text('inkoopPrijs') }} <br>
{{ Form::label('verkoopPrijs:') }}
{{ Form::text('verkoopPrijs') }} <br>
{{Form::label('Fabrieken', 'Fabrieken Id:') }}
{{ Form::select('Fabrieken_Id', $fabrieks)}} <br>
{{ Form::submit('edit')}}
{{ Form::close() }}
如果还有什么我需要添加到问题中的,请告诉我,我会添加它
【问题讨论】:
-
你的函数体中有一个参数,“Request $request, Product $product” 它将从哪里获取?它是如何通过您定义的路线的?
标签: laravel laravel-5.2