where(function ($q) use ($keyword) { $q->where('name', 'like', "%$keyword%") ->orWhere('unit', 'like', "%$keyword%"); }); } public function purchaseRequestMaterials() { return $this->hasMany(PurchaseRequestMaterial::class); } public function suppliers() { return $this->belongsToMany(Supplier::class, 'supplier_material_prices') ->withPivot('description', 'price'); } public function unitPrices() { return $this->belongsToMany(UnitPrice::class, 'unit_price_materials') ->withPivot('qty'); } }