This local scope 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.
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:
<?phpuse 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 scope 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.
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 scope 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.
This global scope is initialized in the UccelloModule trait. As explained in the Laravel official documentation, if you would like to remove it for a given query, use the withoutGlobalScope method:
<?php
// People belonging to the uccello domain and its descendants domains
// and with a name starting with 'John'.
$people = \App\Person::inDomain(ucmodule('uccello'), true)
->where('name', 'like', 'John%')
->get();
<?php
use App\Person;
use Uccello\Core\Models\Domain;
// Apply the filter with the id 1 to the query
$people = Person::filterBy(1)->get();
// Retrieve a filter and apply it to the query
$filter = Filter::find(1);
$people = Person::filterBy($filter)->get();
// Apply a custom filter
$customFilter = [
'conditions' => [
"search" => [
"first_name" => "John"
]
],
'order' => [ 'last_name' => 'asc' ]
];
$people = Person::filterBy($customFilter)->get();
<?php
// Apply the filter with the id 1 to the query
// to people belonging to the uccello domain and its descendants domains
// and with a name starting with 'John'.
$people = App\Person::inDomain(ucmodule('uccello'), true)
->where('name', 'like', 'John%')
->filterBy(1)
->get();