Php Laravel 5.0更新表单不起作用
我有一个form::model,是我在选中记录时创建的。如果我想编辑它,我会得到一个错误。 也就是说:Php Laravel 5.0更新表单不起作用,php,forms,laravel-5,Php,Forms,Laravel 5,我有一个form::model,是我在选中记录时创建的。如果我想编辑它,我会得到一个错误。 也就是说: exception 'InvalidArgumentException' with message 'Route [test/edit] not defined.' in /www/testsite/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:306 routes.php Route::any('test/
exception 'InvalidArgumentException' with message 'Route [test/edit] not defined.' in /www/testsite/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:306
routes.php
Route::any('test/edit','Test\testController@edit');
edit.blade.php
{!! Form::model($display,array('url' => array('test/edit',$display->myID),'method' => 'put')) !!}
{!! Form::label('myID', 'My ID') !!}
{!! Form::text('myID') !!}
{!! Form::label('topic', 'Topic') !!}
{!! Form::text('topic') !!}
<br>
{!! Form::label('describe', 'describe') !!}
{!! Form::text('describe') !!}
<br>
{!! Form::submit('Update') !!}
{!! Form::close() !!}
在laravel中有一个方法“patch”,你可以使用它。它在我的更新功能中为我工作
public function update(Request $request, $id)
{
$this->validate($request, [
'name' => 'required',
'details' => 'required',
]);
$input = $request->all();
if ($request->hasFile('userpic')) {
$userpic = $input['pic'];
$file_path = public_path("avatars/$userpic");
if(File::exists($file_path)) {
File::delete($file_path);
}
$fileName = time().$request->userpic->getClientOriginalName();
$request->userpic->move(public_path('avatars'), $fileName);
$input['userpic'] = $fileName;
}
Product::find($id)->update($input);
return redirect()->route('productCRUD.index')->with('success','Product updated successfully');
}
public function update(Request $request, $id)
{
$this->validate($request, [
'name' => 'required',
'details' => 'required',
]);
$input = $request->all();
if ($request->hasFile('userpic')) {
$userpic = $input['pic'];
$file_path = public_path("avatars/$userpic");
if(File::exists($file_path)) {
File::delete($file_path);
}
$fileName = time().$request->userpic->getClientOriginalName();
$request->userpic->move(public_path('avatars'), $fileName);
$input['userpic'] = $fileName;
}
Product::find($id)->update($input);
return redirect()->route('productCRUD.index')->with('success','Product updated successfully');
}