簡體   English   中英

使用未定義的常量“產品”-Laravel 5.6

[英]Use of undefined constant 'products' - laravel 5.6

以下是我正在執行的教程代碼。 但是當我運行我的應用程序時,我得到了寫作

使用未定義的常量“產品”-Category.php中假定為“產品”

為什么會這樣

PS:對不起,我的英語

類別

 public function products()
   {
    return $this->hasMany(Product::class);
   }    
 public function check_items() 
   {    
    return $this->select(‘product’, DB::raw('count(*) as e.count'))->products()->groupBy(‘product’)->get();  
   }

產品

 protected $fillable = ['product'];

    public function shop() {
      return $this->belongsTo(Shop::class);
    }

    public function category() {
      return $this->belongsTo(Category::class);
    }

視圖

 @forelse ($shop->products as $item)                        
    @foreach ($item->check_items as $p )
     <div>{{$p->product}} ({{$answer->e.count}})</div>
    @endforeach  

您出於某些原因使用智能引號:

‘product’

使用單引號:

'product'

請注意,與第二個版本相比,最上面的引號的粗細和更傾斜的性質。

考慮使用IDE /代碼編輯器,VSCode,Atom或PhpStorm。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM