Download the PHP package mattsplat/table-queries without Composer
On this page you can find all versions of the php package mattsplat/table-queries. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package table-queries
Laravel Table Queries
Contents
What Is It?
Setup
Sorting
Searching
Relationships
Filters
What Is It?
If you need to view your data in table or similar format that combines data from relational models and you need perforance that the client side can't provide. With a large dataset it can become too slow for the client to render so we can use server side rendering. If we rely on data that is from a relational table it can be tricky to filter, search or sort by this data. This package is aimed at making this easier.
Say you have the following database structure
You might need to display a table of users with a column for company name, total number of sales and total amount of sales in the last year.
You can define the company name as a simple belongs to relationships with company|name as company_name'
. This is formatted relation|column as alias
. The relation must be defined on the model.
This will add company_name to the select statement allowing it to be filtered or sorted.
For total sales we can use sales|count(*) as sales_count
In total sales in the last year we want to get the sum of all the sales by using
This works similar to using
but instead of adding the entire relation as nested object it adds a field that can be added to orderBy
or where
or accessed like a property of the model.
Setup
To install with composer run
composer require mattsplat/table-queries
For each query a class that implements TableQueryable is created. This class would typically called from a controller.
Sorting
The TableQueryBuilder class accepts options orderBy
and ascending
which can be passed as part of the setOptions method.
or the order method can be called directly and passed a s arguments
In either case if ascending
is not provided then the default order will be desc
Searching
You can search text across many fields even relations fields using the search option.
or can be called directly
Relationships
Relationships can be loaded using the normal with method but this won't work if you need to sort or filter by this data. With an easy to read syntax you can add basic relational data to the query itself.
Filters
A filter can be called for an specific column using sql like syntax.
Filter array can be passed in the options array in the format filter=column:operator:value
Available Operators Include
Since this doesn't read directly from the request if your request format differs it can modified before sending to the class.
Example get request /users?filter[id]=nin:9&filter[name]=like:S%
All versions of table-queries with dependencies
illuminate/database Version ^6.0
illuminate/console Version ^5.5|^6.0
ext-json Version *
nesbot/carbon Version ^2.24