keyword; if ($keyword) { return $query->where(function($sql) use($keyword) { $sql->where("title", 'like', "%$keyword%"); }); } return $query; } public function shopFood() { return $this->hasOne(Food::class, 'shop_id', 'id'); } public function shopSku() { return $this->hasOne(S2ShopSku::class, 'id', 'skuid'); } public function scopeFoodType($query) { $type = request()->type; if ($type) { return $query->where(function($sql) use($type) { $sql->where("type", $type); }); } return $query->whereHas("shopFood"); } }