Snippets Collections
 trainingRadioBtns.forEach(onHandleCheckbox);

    // Update selectedOptions[] when checkboxes are clicked
    function onHandleCheckbox(checkbox) {
        checkbox.addEventListener("change", () => {
            const status = [...trainingRadioBtns].map((btn) => ({
                value: btn.value,
                checked: btn.checked,
            }));

            checkedValues = status.filter((btn) => btn.checked).map((btn) => btn.value); // selected check values array
            const notSelected = status.filter((btn) => !btn.checked).map((btn) => btn.value); // not selected check values array
            console.log("selected", checkedValues);
            console.log("not selected", notSelected);

            filteredItems = locations.filter((item) => {
                // Prepare each individual match condition for filtering
                // const matchesCategory = checkedValues.includes(item.category);
                const matchesFunded = (checkedValues.includes("funded") && item.funded) || notSelected.includes("funded");
                const matchesOnline = (checkedValues.includes("isAvailableOnline") && item.isAvailableOnline) || notSelected.includes("isAvailableOnline");
                const matchesPartTime = (checkedValues.includes("isAvailablePartTime") && item.isAvailablePartTime) || notSelected.includes("isAvailablePartTime");
                const matchesApprentice = (checkedValues.includes("apprenticeshipTraineeship") && item.apprenticeshipTraineeship) || notSelected.includes("apprenticeshipTraineeship");
                const matchesVetFeeCourse = (checkedValues.includes("isVetFeeCourse") && item.isVetFeeCourse) || notSelected.includes("isVetFeeCourse");

                // Check if the item matches any of the selected filters (OR logic) and return

                return matchesFunded && matchesOnline & matchesPartTime & matchesApprentice & matchesVetFeeCourse;
            });

            // if no items are found on filtering, show a message in the DOM
            if (filteredItems.length === 0) {
                list.innerHTML = `<h4>No items exist with these current filters<h3>`;
            } else {
                displayLocations();
            }
        });
    }
public function index(Travel $travel, ToursListRequest $request)
    {
        $tours = $travel->tours()
            ->when($request->priceFrom, function ($query) use ($request) {
                $query->where('price', '>=', $request->priceFrom * 100);
            })
            ->when($request->priceTo, function ($query) use ($request) {
                $query->where('price', '<=', $request->priceTo * 100);
            })
            ->when($request->dateFrom, function ($query) use ($request) {
                $query->where('starting_date', '>=', $request->dateFrom);
            })
            ->when($request->dateTo, function ($query) use ($request) {
                $query->where('starting_date', '<=', $request->dateTo);
            })
            ->when($request->sortBy, function ($query) use ($request) {
                if (! in_array($request->sortBy, ['price'])
                    || (! in_array($request->sortOrder, ['asc', 'desc']))) {
                    return;
                }

                $query->orderBy($request->sortBy, $request->sortOrder);
            })
            ->orderBy('starting_date')
            ->paginate();

        return TourResource::collection($tours);
    }
const prices = [400.50, 3000, 99.99, 35.99, 12.00, 9500];


// Sorting books by their rating: // use slice to copy the array
const acscendingsOrders = prices.slice().sort((a, b) => a.toFixed(2) - b.toFixed(2))
const descendingOrders = prices.slice().sort((a, b) => b.toFixed(2) - a.toFixed(2))

/** The indexOf() method
	Returns the position of the first occurrence of a value in a string.
	The indexOf() method returns -1 if the value is not found.
	The indexOf() method is case sensitive.
  */


function isValidPassword(password, username) {
	if (
		password.length < 8 ||
		password.indexOf(' ') !== -1 ||
		password.indexOf(username) !== -1
	) {
		return false;
	}
	return true;
}

/** or */


function isValidPassword(password, username) {
	const tooShort = password.length < 8;
	const hasSpace = password.indexOf(' ') !== -1;
	const tooSimilar = password.indexOf(username) !== -1;
	if (tooShort || hasSpace || tooSimilar) return false;
	return true;
}
function betweenYears(yearStart, yearEnd){
    return function(number){
          if(number >= yearStart && number <= yearEnd){
              return number
          }
          return false
    }
}

const myYear = betweenYears(1900, 1999);
myYear(1978);
star

Sun Feb 02 2025 22:43:02 GMT+0000 (Coordinated Universal Time)

#filtering #checkboxes
star

Sat Jan 20 2024 01:44:36 GMT+0000 (Coordinated Universal Time) https://github.com/LaravelDaily/Laravel-Travel-API-Course/blob/main/app/Http/Controllers/Api/V1/TourController.php

#laravel #php #filtering #search #eloquent
star

Wed Apr 12 2023 05:58:05 GMT+0000 (Coordinated Universal Time)

#function #return #values #filtering
star

Wed Apr 12 2023 01:00:20 GMT+0000 (Coordinated Universal Time)

#function #return #values #filtering
star

Wed Apr 12 2023 00:20:59 GMT+0000 (Coordinated Universal Time)

#function #return #values #filtering

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension