Download the PHP package yassinedabbous/laravel-dynamic-query without Composer

On this page you can find all versions of the php package yassinedabbous/laravel-dynamic-query. 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-dynamic-query

Laravel Dynamic Query

A rich set of features designed to make querying a database more dynamic, flexible, and secure.

Table of Content

:sparkles: Features

:small_red_triangle_down: Installation:

composer require yassinedabbous/laravel-dynamic-query

:technologist: Quick Setup

This packages is a set of 4 traits, you can add one of them or just use the general HasDynamicQuery trait:

In your controller, call the needed scopes or just use the dynamicQuery() method:

For more details on usage, see the sections below.

:technologist: Usage:

Select:

Since the API client (FrontEnd developer) doesn't need to know which fields are columns, appends, or model relationships, DynamicFields simplifies the process by automatically handling:

Note: to support deep fields, all requested relations should use DynamicFields.

• API call:

GET /users?_fields=id,name,avatar,followers_count,posts:id|title|time_ago

• Resulting Database Queries:

SELECT `id`, `name`, `avatar`, (SELECT COUNT("id") FROM "followers" where ...) AS `followers_count`  FROM `users`;

SELECT `id`, `title`, `created_at` FROM `posts` WHERE `users_id` = ?;

• Response: ("time_ago", "followers_count" .. are automatically appended)

[
    {
        "id": 1,
        "name": "Someone",
        "avatar": "...",
        "followers_count": 1048,
        "posts": [
            {"id":1, "title":"post 1", "time_ago": "2 weeks ago"},
            ...
        ]
    },
    {
        "id": 1,
        ...
    },
    ...
]

To utilize the dynamic selection feature, you need to define a list of selectable columns, relations, aggregates, and appends within your model.

Dynamic Columns:

Dynamic Relations:

Model relations can be inferred automatically from methods if they are defined with a typed return:

Alternatively, you can manually define the list of allowed relations using the dynamicRelations() method:

Dynamic Appends:

To function properly, appends must be defined along with their dependent columns or relations:

To work correctly, appends must be defined with their dependent columns or relations:

Dynamic Aggregates:

Aggregates can be defined as named scopes or closures:

Filter:

DynamicFilters Allows API consumers to filter queries based on URL parameters, it support multiple clause types and logics:

API Example:

api/endpoint?status_id=20&members_count=3
            &_operators[members_count]=>
            &_clauses[members_count]=having

Dynamic Filters:

To implement dynamic filters, you need to define a list of acceptable filters, optionally with their allowed operators:

Operators:

DynamicFilters uses the equality = operator by default, but this can be changed for each filter using the _operators parameter.

api/products?price=1000&_operators[price]=>

Results in the following SQL query:

SELECT * FROM products WHERE price > 1000

api/products?name=Iphone&_operators[name]=LIKE%

Resulted DB query: SELECT * FROM products WHERE name LIKE "Iphone%"

• Using NOT Logic

To apply the NOT logic, use the exclamation mark (!) before operators:

Operator Query
!= SELECT * FROM table WHERE column != value
!LIKE SELECT * FROM table WHERE !(column LIKE value)
!NULL SELECT * FROM table WHERE column NOT NULL
!IN SELECT * FROM table WHERE column NOT IN (value1, value2 ...)
!BETWEEN SELECT * FROM table WHERE column NOT BETWEEN value1 AND value2
... ...
... ...
• Left and Right LIKE

Use % to specify left or right LIKE conditions:

Operator Query
LIKE SELECT * FROM table WHERE column LIKE "value"
LIKE% SELECT * FROM table WHERE column LIKE "value%"
%LIKE SELECT * FROM table WHERE column LIKE "%value"

Supported operators:

    [
        '=', '<', '>', '<=', '>=', '<>', '!=', '<=>',
        '&', '|', '^', '<<', '>>', '&~', 'is', 'is not',
        'like', '!like', '%like', 'like%',
        'like binary', 'not like', 'ilike',
        'rlike', 'not rlike', 'regexp', 'not regexp',
    ];

Clauses:

DynamicFilters uses WHERE as the default clause, but you can change it with the _clause parameter:

By default, DynamicFilters uses the WHERE clause, but this can be changed using the _clause parameter:

use WHERE clause for all filters:

api/endpoint?_clause=where

use HAVING clause for all filters:

api/endpoint?_clause=having

To apply a clause to a specific filter, use _clauses.

Example:

api/endpoint?price=1000&reviews_count=3&_clauses[reviews_count]=having

Resulting SQL query:

SELECT * FROM products WHERE price = 1000 HAVING reviews_count = 3

Logic operator:

DynamicFilters uses AND by default, but this can be changed using the _logic parameter:

api/endpoint?_logic=and      # use AND clause for all filters
api/endpoint?_logic=or       # use OR clause for all filters

Supported logic clauses are AND and OR.

Scopes:

DynamicFilters support named scopes and closures as filter:

Sorting:

The _sort query parameter specifies the property by which the results will be ordered. By default, sorting is in ascending order, but it can be reversed by prefixing the property name with a hyphen (-).

Operator Query
_sort= id SELECT FROM table ORDER BY id* ASC
_sort= -id SELECT FROM table ORDER BY id* DESC

You can also sort by multiple properties:

/endpoint?_sort=id,-price

or

/endpoint?_sort[]=id&_sort[]=-price

To enable sorting, define a list of allowed sortable fields in your model:

Groups:

The _group query parameter specifies the properties by which the results will be grouped. Grouping is often used with computed values or subqueries (see DynamicFields section).

You can group by one or more properties:

/endpoint?_group=month

/endpoint?_group=month,status

/endpoint?_group[]=month&_group[]=status

To enable grouping, define a list of allowed grouping fields in your model:

Paginate:

Dynamic pagination works similarly to Laravel's paginator but offers more flexibility.

API call example:

/endpoint?page=3&per_page=40

To fetch all records at once, use the _get_all query parameter, optionally limiting the number of results with _limit.

/endpoint?_get_all=true&_limit=50

:gear: Configuration:

You can optionally publish the config file with:

php artisan vendor:publish --tag=dynamic-query-config

These are the contents of the default config file that will be published:

Final result


All versions of laravel-dynamic-query with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
laravel/framework Version ^5.5|^6.0|^7.0|^8.0|^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 yassinedabbous/laravel-dynamic-query contains the following files

Loading the files please wait ....