错误“调用未定义的方法stdClass :: delete()".在尝试删除Laravel中的行时 [英] Error "Call to undefined method stdClass::delete()" while trying delete a row in Laravel
本文介绍了错误“调用未定义的方法stdClass :: delete()".在尝试删除Laravel中的行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从数据库和本地存储中删除图像的方法.
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!');
}
如果我尝试返回$image
的值,则会得到:
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 )
那么我的代码有什么问题?现在我的Laravel版本是4.2.1,但是我尝试将其降级到4.1.17,但是没有任何变化.
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.
推荐答案
根据以下内容更改代码,希望您的问题得到解决..
Change your code according the following and I hope that your problem will be solved..
public function destroy($id) {
$query = DB::table('images')->where('id', '=', $id);
$image = $query->first();
//print_r($image);
//return 'end';
File::delete(public_path() . '/images/gallery/thumb-' . $image->path);
File::delete(public_path() . '/images/gallery/' . $image->path);
$query->delete();
return Redirect::back()
->with('form_success', 1)
->with('form_message', 'Image successfully deleted!');
}
first()和delete()这些函数执行代码.因此,首先将条件分配给变量,然后分别执行.谢谢
first() and delete() these functions execute the code.So first assign your conditions to a variable and then execute them separately.Thanks
这篇关于错误“调用未定义的方法stdClass :: delete()".在尝试删除Laravel中的行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文