Download the PHP package djl997/laravel-search-query-builder without Composer

On this page you can find all versions of the php package djl997/laravel-search-query-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-search-query-builder

Laravel Search Query Builder

Latest Version on Packagist Total Downloads

Laravel Search Query Builder is a Illuminate\Database\Query\Builder macro to easily search on multiple database columns and model relationships.

Let's imagine a case where you want to return all users with something in their name or bio field.

This example is not very difficult to achieve in Laravel, but it can grow very quickly, especially if you also want to search in model relationships like posts or comments for example.

Let's see how the Laravel Search Query Builder package can improve this situation.

Requirements

Laravel Search Query Builder requires PHP 8+ and Laravel 9+.

Installation

You can install the package via composer:

Usage

Basic search term

The most basic call to the search method requires two arguments:

  1. an array of columns,
  2. the search value.

For example, the following query retrieves users where the name column or the value of the bio column is like "Cesar".

This will generate a query where "Cesar" is LIKE the name or LIKE bio column. For clarification, the search term is wrapped between %...% to check if (a part of) the string is present.

Multiple search terms

You can also perform multiple searches at once by separating them with a komma.

This will generate a query for each part of the search term, exploded on a , by default.

Change the separator

If you want to change the delimiter, you can do so by changing the third argument.

This will generate a query for each part of the search term, exploded on a |.

Search multiple relationships

As you probably know, the whereHas method gives you a lot of power to define additional query constraints. And you guessed it, you can use the search method here as well.

For example, the following query will return all users with "Laravel is cool" in their bios + all users who write posts that include this phrase in the title or body.

Combine search with other queries

Since the search method is developed to be a macro and extend the Illuminate\Database\Query\Builder it can be used inline with any other Builder methods such as whereIn, withTrashed or orderBy, or your very own macros.

This will return a ordered list of users with author-, or reviewer roles (deleted AND non-deleted), with "Laravel is cool" in their bios, published posts or comments, ordered by name.

Note! The search query is wrapped in a where query, because you most likely don't want the 'orWheres' to bypass any other filters.

Dynamic columns search

This is a short-sighted example of how you can also make the columns dynamic:

Changelog

Please see the GitHub releases for more information on what has changed recently.

Contributing

Contributions or ideas are welcome.

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-search-query-builder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
laravel/framework Version ^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package djl997/laravel-search-query-builder contains the following files

Loading the files please wait ....