我是 Laravel 的初學(xué)者。我做了一個功能來顯示帶有過濾器的產(chǎn)品列表。我的代碼有一個小問題我有這個代碼:class Product extends Model{ use ScopeActiveTrait; use Slugable; public function setNameAttribute($value) { $this->attributes['name'] = $value; $this->attributes['slug'] = $this->makeSlug($value); } protected $fillable = ['delivery_time', 'product_type', 'name', 'title', 'description', 'keywords', 'content', 'vat_id', 'main_category_id', 'enable', 'slug', 'small_description']; protected $quarded = ['id']; public $timestamps = false; public function vat() { return $this->belongsTo('App\Models\VAT', 'vat_id'); } public function category() { return $this->belongsTo('App\Models\Category', 'main_category_id'); } public function selectedCategory() { return $this->hasMany('App\Models\SelectedProductCategory', 'product_id', 'id'); } public function related() { return $this->belongsTo('App\Models\RelatedProduct'); } public function features() { return $this->hasMany('App\Models\SelectedProductFeature'); } public function frontImage() { return $this->hasMany('App\Models\UploadImage', 'file_id', 'id')->orderBy('order', 'ASC')->where('file_type', 'products'); }}
1 回答

慕森王
TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個贊
在這種情況下,您將無法將額外的參數(shù)傳遞給匿名函數(shù)- 因此$filterDrawer會出現(xiàn)null錯誤。試試這個:
$query->whereHas('features', function ($query) use ($filterDrawer) {
// code
});
- 1 回答
- 0 關(guān)注
- 132 瀏覽
添加回答
舉報(bào)
0/150
提交
取消