Download the PHP package bakgul/laravel-query-helper without Composer

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

Laravel Query Helper

This package aims to add a handy and quite flexible features to Laravel's Eloquent query builder.

Installation

First, install package.

Next, pulish config.

Usage

Filtering

First, you need to add IsFilterable trait and an array of filters to each model where you want to apply filters. That array can have two keys:

Let's say we have the following models and relations.

When you call filter method, it will generate a filtering array throughout the filters array on models starting from User recursively.

To prevent infinite loop in recursion, we stop each branch when they go back to main class after adding main class to the tree. That means You can filter by the following logic:

Since it's an expensive operation to construct the filtering array, we will cache it when it's created first time.

$request->filters should be in a structure like the example down below. The important things here:

The example up above will filter the users based on the following list:

Polymorphic Relationship Filter

Unlike other relationships, polymoprphic ones should be listed under the self key of $filters array.

The filter in request should be like this:

Groupping

Groupping operates on PHP level. If you want to group your data in the database level, you can't use this part. Otherwise, this is how to use it:

group method can be found in IsGrouppable trait as scopeGroup and it accepts the following arguments:

But what if you want to group users with a column that doesn't exist. You can do that thanks to modifiers that are shipped in the package and can be be found on src/Modifiers.

The modifiers will change the sql query to add new field on the fly. For example:

The method up above will add year and email_provider fields to the each user. year will be extracted from updated_at while email_provider from email. Each user will contain selected 3 columns and these 2.

Modifiying

This is used by groupping functionality, and it's already explained, but just as a remainder, you can use it out of grouping too.

Sorting

It's a quite simple method that allowes you to pass all sorting columns in one method.

Extending Functionalities

Filtering

In order to extend available filters, all you need to do is to create your own filter classes and use them in models. Let's say you have a table that contains city and need to apply a filter to it.

First create a class. The class name must be the pascal case version of the key that you will pass in request.

Or you can create your own filtering logic instead of using Text filter.

After you create your new filter class, add it to model which can use it.

Now, you can filter addresses based on city, or users who is in that city/cities.

Groupping

If you want to use one of your current columns as they are, you don't need to take any action. Simply pass the column name in the array of group keys.

But let's say you have domain column where you store the web sites' adresses and you want to group them beased on top-level domain (.com, .net, etc.)

First you need a modifier to extract that part and store it in a new field in query.

Then you need to add it to modifiers array in config/query-helper.php

Now you can use it like so:

License

This is open-sourced software licensed under the MIT license.


All versions of laravel-query-helper with dependencies

PHP Build Version
Package Version
Requires bakgul/laravel-helpers Version ^1.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 bakgul/laravel-query-helper contains the following files

Loading the files please wait ....