Download the PHP package crhg/eloquent-exists-relation without Composer
On this page you can find all versions of the php package crhg/eloquent-exists-relation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crhg/eloquent-exists-relation
More information about crhg/eloquent-exists-relation
Files in crhg/eloquent-exists-relation
Package eloquent-exists-relation
Short Description Add withExits method to check existence of related records with subquery.
License MIT
Informations about the package eloquent-exists-relation
DESCRIPTION
Add an attribute that indicates whether there is an element indicated by the relation specified when acquiring to the Eloquent Model using a subquery.
It is similar to withCount
, which finds the number of elements of a relation, but it differs in obtaining only whether it exists without counting.
INSTALL
This package is compliant with Package Discovery so no additional configuration is required.
In case of Lumen
Register EloquentExistsRelationProvider
as follows in bootstrap/app.php
.
USAGE
If you want to know wheather results from a relationship exists without actually loading them you may use the withExists
method, which will place a {relation}_exists column on your resulting models. For example:
You may add the "exists" for multiple relations as well as add constraints to the queries:
You may also alias the relationship exists result, allowing multiple exists on the same relationship:
TIPS
Since the value of EXISTS may not be a boolean value (for example, 0 or 1 in mysql), it is convenient to cast it explicitly when you want to treat it as a boolean value.
All versions of eloquent-exists-relation with dependencies
illuminate/database Version ^5.6,>=5.6.12 || ^6.0
illuminate/support Version ^5.6,>=5.6.12 || ^6.0