使用未定义的常量“产品”-Laravel 5.6

时间:2018-07-12 10:23:14

标签: php laravel

以下是我正在执行的教程代码。但是当我运行我的应用程序时,我得到了写作

  
    

使用未定义的常量“产品”-在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  

1 个答案:

答案 0 :(得分:3)

您出于某些原因使用智能引号:

‘product’

使用单引号:

'product'

请注意与第二个版本相反,最上面的引号的粗细和倾斜的性质。

考虑使用IDE /代码编辑器,VSCode,Atom或PhpStorm。