Download the PHP package protonemedia/laravel-cross-eloquent-search without Composer

On this page you can find all versions of the php package protonemedia/laravel-cross-eloquent-search. 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-cross-eloquent-search

Laravel Cross Eloquent Search

Latest Version on Packagist run-tests Total Downloads Buy us a tree

This Laravel package allows you to search through multiple Eloquent models. It supports sorting, pagination, scoped queries, eager load relationships, and searching through single or multiple columns.

Sponsor this package!

❤️ We proudly support the community by developing Laravel packages and giving them away for free. If this package saves you time or if you're relying on it professionally, please consider sponsoring the maintenance and development. Keeping track of issues and pull requests takes time, but we're happy to help!

Requirements

Features

📺 Want to watch an implementation of this package? Rewatch the live stream (skip to 13:44 for the good stuff): https://youtu.be/WigAaQsPgSA

Blog post

If you want to know more about this package's background, please read the blog post.

Installation

You can install the package via composer:

Upgrading from v2 to v3

Upgrading from v1 to v2

Usage

Start your search query by adding one or more models to search through. Call the add method with the model's class name and the column you want to search through. Then call the search method with the search term, and you'll get a \Illuminate\Database\Eloquent\Collection instance with the results.

The results are sorted in ascending order by the updated column by default. In most cases, this column is updated_at. If you've customized your model's UPDATED_AT constant, or overwritten the getUpdatedAtColumn method, this package will use the customized column. If you don't use timestamps at all, it will use the primary key by default. Of course, you can order by another column as well.

If you care about indentation, you can optionally use the new method on the facade:

There's also an when method to apply certain clauses based on another condition:

Wildcards

By default, we split up the search term, and each keyword will get a wildcard symbol to do partial matching. Practically this means the search term apple ios will result in apple% and ios%. If you want a wildcard symbol to begin with as well, you can call the beginWithWildcard method. This will result in %apple% and %ios%.

Note: in previous versions of this package, this method was called startWithWildcard().

If you want to disable the behaviour where a wildcard is appended to the terms, you should call the endWithWildcard method with false:

Multi-word search

Multi-word search is supported out of the box. Simply wrap your phrase into double-quotes.

You can disable the parsing of the search term by calling the dontParseTerm method, which gives you the same results as using double-quotes.

Sorting

If you want to sort the results by another column, you can pass that column to the add method as a third parameter. Call the orderByDesc method to sort the results in descending order.

You can call the orderByRelevance method to sort the results by the number of occurrences of the search terms. Imagine these two sentences:

If you search for Apple iPad, the second sentence will come up first, as there are more matches of the search terms.

Ordering by relevance is not supported if you're searching through (nested) relationships.

To sort the results by model type, you can use the orderByModel method by giving it your preferred order of the models:

Pagination

We highly recommend paginating your results. Call the paginate method before the search method, and you'll get an instance of \Illuminate\Contracts\Pagination\LengthAwarePaginator as a result. The paginate method takes three (optional) parameters to customize the paginator. These arguments are the same as Laravel's database paginator.

You may also use simple pagination. This will return an instance of \Illuminate\Contracts\Pagination\Paginator, which is not length aware:

Constraints and scoped queries

Instead of the class name, you can also pass an instance of the Eloquent query builder to the add method. This allows you to add constraints to each model.

Multiple columns per model

You can search through multiple columns by passing an array of columns as the second argument.

Search through (nested) relationships

You can search through (nested) relationships by using the dot notation:

Full-Text Search

You may use MySQL's Full-Text Search by using the addFullText method. You can search through a single or multiple columns (using full text indexes), and you can specify a set of options, for example, to specify the mode. You can even mix regular and full-text searches in one query:

If you want to search through relationships, you need to pass in an array where the array key contains the relation, while the value is an array of columns:

Sounds like

MySQL has a soundex algorithm built-in so you can search for terms that sound almost the same. You can use this feature by calling the soundsLike method:

Eager load relationships

Not much to explain here, but this is supported as well :)

Getting results without searching

You call the search method without a term or with an empty term. In this case, you can discard the second argument of the add method. With the orderBy method, you can set the column to sort by (previously the third argument):

Counting records

You can count the number of results with the count method:

Model Identifier

You can use the includeModelType to add the model type to the search result.

By default, it uses the type key, but you can customize this by passing the key to the method.

You can also customize the type value by adding a public method searchType() to your model to override the default class base name.

Standalone parser

You can use the parser with the parseTerms method:

You can also pass in a callback as a second argument to loop through each term:

Testing

Changelog

Please see CHANGELOG for more information about what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Other Laravel packages

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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

Treeware

This package is Treeware. If you use it in production, we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest, you'll create employment for local families and restoring wildlife habitats.


All versions of laravel-cross-eloquent-search with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2|^8.3
illuminate/support Version ^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 protonemedia/laravel-cross-eloquent-search contains the following files

Loading the files please wait ....