douci1677
2014-06-02 12:06
浏览 99
已采纳

错误“在Laravel中尝试删除行时调用未定义的方法stdClass :: delete()”

My method to delete an image from database and local storage.

public function destroy($id) {
        $image = DB::table('images')->where('id', '=', $id)->first();
        //print_r($image);
        //return 'end';
        File::delete(public_path() . '/images/gallery/thumb-' . $image->path);
        File::delete(public_path() . '/images/gallery/' . $image->path);
        $image->delete();
        return Redirect::back()
                        ->with('form_success', 1)
                        ->with('form_message', 'Image successfully deleted!');
    }

If I try to return value of $image I get:

stdClass Object ( [id] => 49 [site_id] => 1 [page_id] => [location] => gallery [alt] => [path] => 60e52a2755ffe8923d5ac1232f5d9154.jpg ) 

So what's wrong with my code? Now my Laravel version is 4.2.1, but i try to downgrade him to 4.1.17, but no changes.

图片转代码服务由CSDN问答提供 功能建议

我从数据库和本地存储中删除图像的方法。

 <  code> public function destroy($ id){
 $ image = DB :: table('images') - &gt; where('id','=',$ id) - &gt; first(); 
 /  / print_r($ image); 
 // return'end'; 
 File :: delete(public_path()。'/ images / gallery / thumb-'。$ image-&gt; path); 
 File ::  delete(public_path()。'/ images / gallery /'。$ image-&gt; path); 
 $ image-&gt; delete(); 
返回Redirect :: back()
  - &gt; with('  form_success',1)
  - &gt; with('form_message','Image successfully deleted!'); 
} 
   
 
 

如果我尝试返回值 $ image 我得到:

  stdClass Object([id] =&gt; 49 [site_id] =&gt; 1 [page_id] =&gt;  [location] =&gt;图库[alt] =&gt; [路径] =&gt; 60e52a2755ffe8923d5ac1232f5d9154.jpg)
   
 
 

那么我的代码出了什么问题? 现在我的Laravel版本是4.2.1,但我尝试将他降级到4.1.17,但没有变化。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题