【发布时间】:2019-12-04 11:17:10
【问题描述】:
我得到错误:
错误异常 (E_NOTICE) 未定义的属性:Illuminate\Database\Query\Builder::$name" 当我在浏览器中使用链接运行 Laravel 应用程序时:http://127.0.0.1:8000/api/products!
帮我解决这个bug非常感谢(我是学习Laravel的新手,谢谢!!!)]
【问题讨论】:
-
分享你的代码。
-
您好,您可以通过文本粘贴您的代码 sn-ps。图片是额外的。您也可以在代码的开头使用 3 个符号“`”和结尾的 3 个“`”来格式化代码。
-
带有函数索引的控制器: public function index() { return ProductCollection::collection(Product::all()); }
-
和 ProductCollection 中的代码: public function toArray($request) { return [ 'name' => $this->name, 'totalPrice' => round( (1- ($this->discount /100))*$this->price,2), 'rating' => $this->reviews->count()> 0 ?round($this ->reviews->sum('star')/$this ->reviews->count(),2) :'No rating yet', 'href' => [ 'link' => route('products.show',$this->id) ] ]; }