我只分享最重要的一段代码
$product = DB::table('products')->where('id','=',$pid)->get();
//the above code makes no errors
if ($product[0]::sale == '1') // this line of code makes error
{
//$cost+=($product[0]->price - ($product[0]->discount*$product[0]->price/100));
}
else
{
//$cost+=$product[0]->price;
}
这条线很清楚 if ($product[0]::sale == '1')
犯错误
但是我无法捕获它-当我发送请求时-我只收到500(内部服务器错误)-我无法捕获错误
--更新
return$product//出错
返回var\u dump($product);
还这个
object(stdClass)#234 (23) {
["title"]=>
string(16) "oihoh jewioh 234"
["id"]=>
string(9) "hew7h23iu"
["desciption"]=>
string(162) "ewhniuhewch2398h9h32
32dh2398dh23dh3
d2h3d8h238dh2389hd98
3d2hd8932hd8h23329dj892
j9hd2dh8723gd7g32d
23dh9832hd8h2389dh9h239dh239
23d8h3289dh3298d9h32dh329h"
["sizes"]=>
string(4) "M,XL"
["colors"]=>
string(14) "#12f,#caf,#afa"
["amount"]=>
int(12)
["category"]=>
string(5) "Women"
["scategory"]=>
string(5) "Lambs"
["featured"]=>
int(1)
["minfo"]=>
string(23) "sia:deuw,on:iej,od:jdiw"
["images"]=>
string(288) "snoicds,nconew,ncoiwenioew,http://www.ridgetopvirtualsolutions.com/wp-content/uploads/2014/03/product-that-sells-4-ridgetopvirtualsolutions.jpg*snoicdse,nconew,ncoiwenioew,http://www.ridgetopvirtualsolutions.com/wp-content/uploads/2014/03/product-that-sells-4-ridgetopvirtualsolutions.jpg"
["video"]=>
NULL
["fimage"]=>
string(143) "snoicds,nconew,ncoiwenioew,http://www.ridgetopvirtualsolutions.com/wp-content/uploads/2014/03/product-that-sells-4-ridgetopvirtualsolutions.jpg"
["sale"]=>
int(0)
["price"]=>
float(26.5)
["sold"]=>
int(32)
["views"]=>
int(14)
["likes"]=>
int(24)
["discount"]=>
NULL
["dexpire"]=>
NULL
["created_at"]=>
NULL
["updated_at"]=>
NULL
["avgreview"]=>
float(3.4)
}
1条答案
按热度按时间knsnq2tg1#
使用查询生成器时,不应该收到这种类型的错误。因为你把它当作一个数组。我们都做过。
好消息是,比这好多了!用途:
然后使用下面的代码检查产品是否存在。