Php 在还原软删除时调用未定义的方法stdClass::restore()
我正在尝试还原软删除的数据,但一直出现此错误 我的路线是这样的Php 在还原软删除时调用未定义的方法stdClass::restore(),php,laravel-5,Php,Laravel 5,我正在尝试还原软删除的数据,但一直出现此错误 我的路线是这样的 Route::resource('/dvd', 'DvdController'); Route:get('dvd/{id}/restore', 'DvdController@restore'); 这是我的控制器 public function restore($id) { //Dvd::withTrashed()->where('id','=',Input::get('id'))->r
Route::resource('/dvd', 'DvdController');
Route:get('dvd/{id}/restore', 'DvdController@restore');
这是我的控制器
public function restore($id)
{
//Dvd::withTrashed()->where('id','=',Input::get('id'))->restore();
//Dvd::find($id)->restore();
$dvds = DB::table('dvds')->where('id', $id)->first();
$dvds->restore($id);
$view = redirect('dvd')->with('message', 'Data berhasil di-restore');
return $view;
}
我通过按钮调用该方法
<a style="margin-bottom: 5px;" class="btn btn-small btn-primary btn-block"
href="{{ URL('dvd/' . $data->id . '/restore') }}">Restore</a>
我不知道我错了什么,我是PHP和laravel的新手,请包含正确的代码。
谢谢您使用的是DB facade,因此您得到的是一个StdClass实例,而不是一个雄辩的模型,restore()是雄辩类上的一个方法 您需要更改:
$dvds = DB::table('dvds')->where('id', $id)->first();
例如:
$dvds = Dvd::withTrashed()->where('id', $id)->first();
然后它就可以正常工作了