Query Scopes

Definition

A Query Scope is a sort of complex condition you can add easily to an Eloquent Query.

circle-info

For more information about Query Scopes, please refer to the Laravel official documentationarrow-up-right.

By default, Uccello provides 3 query scopes:

  • inDomain

  • filterBy

  • assignedUser

Default Query Scopes

inDomain

This local scopearrow-up-right allows to easily filter the records of a module, to visualize only those of the current domain or its child domains if the descending view is activated.

circle-info

This scope is activated only if the module contains a domain_id column in this related database table.

The following example will retrieve all people related to the domain with the slug uccello:

<?php

use App\Person;
use Uccello\Core\Models\Domain;

$domain = ucdomain('uccello');

// Only people belonging to the uccello domain
$people = Person::inDomain($domain)->get();

 // People belonging to the uccello domain and its descendants domains
$people = Person::inDomain($domain, true)->get();

You can use this scope with other conditions:

filterBy

This local scopearrow-up-right allows to filter records of a module. You can pass a filter's id, a filter object or an array containing the description of the filter you want to apply.

circle-info

If you use an existing filter, only the conditions and the sort order will be applied. The columns definition will be ignored.

You can use this scope with other conditions:

assignedUser

This global scopearrow-up-right is automatically applied by default to all queries of all private modules and allows to retrieve records only if there are assigned to the authenticated user of to a group to which he belongs. It is applied only if a column assigned_user_id exists in the database table related of the module. For more information see AssignedUser Uitype documentation.

circle-info

This global scope is initialized in the UccelloModulearrow-up-right trait. As explained in the Laravel official documentationarrow-up-right, if you would like to remove it for a given query, use the withoutGlobalScope method:

People::withoutGlobalScope(\Uccello\Core\Support\Scopes\AssignedUser::class)

Last updated

Was this helpful?