2016-01-10 51 views
1

我試圖恢復softdeleted數據,但我只是不停收到此錯誤 Call to undefined method stdClass::restore()調用未定義的方法stdClass的::關於恢復軟刪除

我的路線恢復()這個樣子

Route::resource('/dvd', 'DvdController'); 
    Route:get('dvd/{id}/restore', '[email protected]'); 

這是我的控制器

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上的新手,請包含正確的代碼。 謝謝

回答

2

您正在使用數據庫門面,因此您得到一個StdClass實例作爲結果,而不是一個Eloquent模型和restore()是一個Eloquent類的方法。

你需要改變:

$dvds = DB::table('dvds')->where('id', $id)->first(); 

喜歡的東西:

$dvds = Dvd::withTrashed()->where('id', $id)->first(); 

,然後它才能正常工作。

相關問題