Download the PHP package aw-studio/laravel-model-index without Composer
On this page you can find all versions of the php package aw-studio/laravel-model-index. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aw-studio/laravel-model-index
More information about aw-studio/laravel-model-index
Files in aw-studio/laravel-model-index
Package laravel-model-index
Short Description Filterable, sortable, searchable index listing for laravel models
License MIT
Homepage https://github.com/aw-studio/model-index
Informations about the package laravel-model-index
Laravel Model Index
Overview
This package provides an easy to use Query Builder to filter, sort, search, and paginate Laravel models.
Usage
Install the package via composer:
The model to which the index endpoint refers must have the following trait added:
Filtering
The Index Query Builder supports filtering from query parameters nearly out of the box. All you have to do is to configure which model attributes are filterable. This can be done when using the index in the controller:
Or if you'd like to resue the Index multiple times and always have the same filter options enabled, you may add a filterable
property or method to the Model which should return an array attribute names.
Filtering the index list is now as simple as adding the query parameter “filter” to the URL with the attribute name as the key and a value. For example:
Advanced Filtering
For more sophisticated filters, you may use operators and logical operators in the query parameters. For example:
The following operators are supported:
$eq
- Equal$ne
- Not equal$gt
- Greater than$gte
- Greater than or equal$lt
- Less than$lte
- Less than or equal$in
- In$notIn
- Not in$contains
- Contains$notContains
- Not contains$between
- Between$startsWith
- Starts with$endsWith
- Ends with$null
- Null$notNull
- Not null
Logical operators can be used to combine filters. For example:
The following logical operators are supported:
$and
$or
Custom Filters
By default filter keys are supposed to match the column names of the model.
You can also define custom filter keys by using the filter
method on the Index query and define custom callbacks for the filter.
This also allows you to use model scopes for filtering or more complex queries e.g. in related models.
Sorting
You can sort the index using query parameters. For example:
You can also sort in descending order:
Multiple columns can be sorted by separating them with a comma:
Searching
You can search the index using query parameters. For example:
This will search all configured columns for the term "John".
Configuring Searchable Columns
To configure which columns should be searchable, use the searchable
method on the
Index query:
Pagination
You can automatically paginate the index using query parameters by adding the page
query parameter to the URL or setting a per_page value in the query parameters. For example:
License
This project is licensed under the MIT License. See the LICENSE file for details.