public function scopeSearch(Builder $query, ?string $search = null, ?string $lang = null): Builder 	{ 		$search = preg_replace('/\s+/', '%', $search ?? ''); 		$search = empty($search) ? null : '%' . $search . '%';  		return !$search ? $query : $query->where(function ($query) use ($search) { 			$query->where('name', 'like', $search) 				->orWhere('slug', 'like', $search) 				->orWhere('extra_name', 'like', $search) 				->orWhere(function ($query) use ($search) { 					$query->searchByTag($search); 				}); 		})->when($lang && ($lang !== static::defaultTranslationLocale()), function ($query) use ($search) { 			$query->orWhere(function ($query) use ($search) { 				$query->whereHas('translations', function ($query) use ($search) { 					$query->where('column', 'name')->where(function ($query) use ($search) { 						$query->orWhere('value', 'like', $search); 					})->orWhere('column', 'slug')->where(function ($query) use ($search) { 						$query->orWhere('value', 'like', $search); 					})->orWhere('column', 'extra_name')->where(function ($query) use ($search) { 						$query->orWhere('value', 'like', $search); 					}); 				}); 			})->orWhere(function ($query) use ($search) { 				$query->whereHas('tags', function ($query) use ($search) { 					$query->whereHas('tag', function ($query) use ($search) { 						$query->whereHas('translations', function ($query) use ($search) { 							$query->where('column', 'name')->where(function ($query) use ($search) { 								$query->orWhere('value', 'like', $search); 							}); 						}); 					}); 				}); 			}); 		}); 	}