I have a form::model I created when a record is selected information is displayed in a form if I want to edit it, I get an error. That says:
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() !!}
testController.php
public function edit($id,Request $request)
{
$myID = $request->myID;
$topic = $request->topic;
$descibe = $request->descibe;
$validator = \Validator::make(
array(
'myID' => $myID,
'topic' => $topic,
'descibe' => $descibe
), array(
'myID' => 'required|min:1',
'topic' => 'required|min:2',
'descibe' => 'required|min5'
)
);
$test = Test::find($id);
$test->save();
}
There is a method "patch" given in laravel, You can use it. Its working for me in my update function ie
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');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.