Download the PHP package alexmg86/laravel-sub-query without Composer

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

Social Card of Laravel Sub Query

Laravel Sub Query

PHP Composer Total Downloads Latest Stable Version License

Why is this package needed?

With standard use of Laravel, if you want the sum or find the maximum column value in the related model, you will have two database queries. What if you need to get a list of one hundred records? With this methods, it all turns into one query to the database and there is no need to load extra data.

I've also added methods for sorting by related model, or when you only need to get one latest or oldest related model for each model without multiple queries. And there is a lot more to speed up your development and code readability.

I often use this in my work and I hope it will be useful to you!

Changelog

Please see CHANGELOG for more information what has changed recently.

Say thank you

If you liked this package, please give me a star.

Installation

Install via composer

Use LaravelSubQueryTrait trait in your model.

Usage

If you want to get results from a relationship without actually loading them and by one request to the database you may use the these methods, which will place a new columns on your resulting models. For example:

The resulting value can be casting through the third parameter. Some types for example: date, datetime, time, char, signed, unsigned, binary.

The following methods apply to all methods!!!

You may add the sum for multiple relations as well as add constraints to the queries:

You may also alias the relationship sum result, allowing multiple sums on the same relationship:

If you're combining withSum with a select statement, ensure that you call withSum after the select method:

In addition, using the loadSum method, you may load a relationship sum columns after the parent model has already been retrieved:

If you need to set additional query constraints on the eager loading query, you may pass an array keyed by the relationships you wish to load. The array values should be Closure instances which receive the query builder instance:

And of course it is all compatible with scopes in models.

Sorting

If you want to sort by field in a related model, simply use the following method:

or with conditions

By default, sorting is by max and desc, you can choose one of the options max, min, sum, avg, desc, acs.

Working with columns

To add or multiply the required columns use this method:

Columns will be summed by default, you can choose one of the options +, -, *, / and set a new name.

Working with dates

A more convenient way to select by dates. By default, sorting is by created_at.

Load latest or oldest relation

Imagine you want to get a list of 50 accounts, each with 100 items. By default, you will get 5000 positions and select the first ones for each account. PHP smokes nervously on the sidelines.
Wow! Now you can load only one latest or oldest related model:

or with conditions

You can use this with relation types hasMany, belongsToMany and hasManyThrough.

Limit relations

If you want to load related model with limit, simply use the following method:

or with conditions

Note that first you write the name of the relation, and then the number of rows.

Caching

For convenience, you can now cache the received data.

A more detailed description is here

Sugar

I got tired of writing some things in detail and I decided to remove them in methods.
You can see it here


All versions of laravel-sub-query with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.4
illuminate/support Version >=5.4
laravel/framework Version >5.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 alexmg86/laravel-sub-query contains the following files

Loading the files please wait ....