Download the PHP package ahmedabdo/searchable without Composer

On this page you can find all versions of the php package ahmedabdo/searchable. 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 searchable

Searchable

Laravel Searchable is package that adds easy customizable searching and filtering ability to Laravel Eloquent Models

Installation

Searching

Search Usage Example

Search Columns

To define the search columns for a model, you can utilize a property decorated with the #[SearchColumns] attribute. This property will contain the default columns for searching the model, as well as any relations that need to be eagerly loaded. In case the #[SearchColumns] attribute is not set, the fillable columns will be used as a fallback.

Custom Search

If you wish to customize the search query for a specific column, you can create a method with the #[Search("colname")] attribute and craft a custom query specifically for that chosen column.

In the example above, the "time" column is stored in the database as a datetime value. If you wish to customize the search functionality for this column by adding a new orWhere statement for searching by day name, you can employ the #[SearchAdd("colname")] attribute.

By utilizing this attribute, you can incorporate the desired orWhere statement into the column search query, while still leveraging the existing search query provided by the package.

[!NOTE]
you may use as many searchAdd methods as you want.

If you have used either #[Search("colname")] or #[SearchAdd("colname")] to customize relation search, the builder instance passed to the custom method will be the builder for the relation model.

Overwrite Default Columns

If you want to override the columns defined in the model, you can pass the columns as a second parameter to the search scope.

Search Options

You can add an options array for columns

The column can have three options

option description values default
operator the operator used for searching operation Avaliable Operators likeContains
useCustom if it uses search method that has #[Search(”col”)] true or false true
useAddCondition if it uses search methods that has #[SearchAdd(”col”)] true or false true

Filtering

Filter Usage Example

Filtering Columns

By default, the columns used for filtering will be those defined in the property with the #[SearchColumns] attribute, combined with the columns specified in the fillable array. If you wish to use different columns as the default for filtering, you can define a property with the #[FilterColumns] attribute.

Filter Query String

The query string parameter names should match to the column names. If you are filtering a relation, you can use a colon : as a separator between the relation name and the column name, instead of a dot . The query string should follow to this pattern.

If you have used a parameter name that differs from the column name, you can pass both the column name and the filter value to the filter scope.

Operators

The operators allowed for filtering include any operator that can be sent to the where builder method, plus additional operators.

Operator Description Example
“contains” or “cont” filtering out entries where the column value contains the given value ?name=cont|ahmed
“startsWith” or “sw” filtering out entries where the column value starts with the given value ?name=sw|ahmed
“endsWith” or “ew” filtering out entries where the column value ends with the given value ?name=ew|abdo
“In” filtering out entries where the column value exists in the given values ?role_id=in|1,2,3,4,5
“notIn” filtering out entries where the column value dosen’t exists in the given values ?role_id=notIn|1,5
“is_null” filtering out entries where the column value is null ?role_id=is_null|
“is_not_null” filtering out entries where the column value is not null ?role_id=is_not_null|
“from” filtering out entries where the date column value is after the given value ?created_at=from|2010-01-01
“from_eq” filtering out entries where the date column value is after or equal the given value ?created_at=from_eq|2010-01-01
“to” filtering out entries where the date column value is before the given value ?created_at=to|2010-01-01
“to_eq” filtering out entries where the date column value is before or equal the given value ?created_at=to_eq|2010-01-01
“from_time” same as “from” but for time ?time=from_time|12:30
“from_time_eq” same as “from_eq” but for time ?time=from_time_eq|12:30
“to_time” same as “to” but for time ?time=to_time|12:30
“to_time_eq” same as “to_eq” but for time ?time=to_time_eq|12:30
“between” or “bt” filtering out entries where column value lies in the given range ?created_at=bt|2010-01-01,2015-01-01&role_id=bt|3,5
“betweenEqual” or “bte” filtering out entries where column value lies in given range with boundry ?created_at=bte|2010-01-01,2015-01-01&role_id=bte|3,5
“where” statement operators any operator used in “where” method can be used as filter operator ?age=<|20&gender=male

[!NOTE]
When using the "between" operator, two arguments must be provided, separated by a comma. If the from argument is not specified, the data will be filtered from negative infinity up to the to argument. Similarly, if the to argument is not provided, the data will be filtered up to positive infinity. For example: ?created_at=bt|,2010-01-01 retrieves all records created before January 1, 2010. Another example: ?created_at=bt|2010-01-01, retrieves all records created after January 1, 2010.

Filter Modes

there is two filter modes and mode and or mode the default mode is and
for changing the mode

Filter Blade Script

If you are utilizing regular Blade templates for the frontend, there is a simple JavaScript script available that simplifies the creation of filter forms. To include this script, add the @searchableScripts directive to your main layout.

then you can create filter form like by following steps

Usage:

Filter Helpers

filterParam

The "filterParam" helper function is utilized to extract the filter value from the query string. This helper function should be utilized when employing a blade filter form, especially if the input field name differs from the corresponding column name.

filterValue

The "filterValue" helper is employed to retrieve the value utilized for filtering in order to display this value in the input field, as an illustrative example.

Custom Operators

In case you need to define a custom operator for filtering and searching, there are two distinct approaches available.

[!NOTE] custom operator must start with sp_

In Config
To publish the configuration file, execute the following command

Once the configuration file has been published, you have the option to define your custom operators within the operators array.

In Service Provider

Additionally, you can register your custom operators within the boot method of one of the service providers.


All versions of searchable with dependencies

PHP Build Version
Package Version
No informations.
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 ahmedabdo/searchable contains the following files

Loading the files please wait ....