# Domain

## Definition

A domain is a **universe** in which data can be **partitioned**. Domains can be used to manage multiple companies in the same Uccello application or to create a business application in which your customers will only have access to data about them.

It is possible to create a **domain tree** to prioritize domains and make it easy to view all the data contained in the subdomains.

{% hint style="info" %}
Uccello uses the library [gzero/eloquent-tree](https://github.com/AdrianSkierniewski/eloquent-tree) to easily manage the domain tree.
{% endhint %}

## Slug

Uccello use the library [cviebrock/eloquent-sluggable](https://github.com/cviebrock/eloquent-sluggable) to generate unique identifier for each domain. A slug allows to retrieve a domain from an URL. A slug is generated from a domain's name.

For example the slug of the domain called **Uccello** is `uccello` and the slug of the domain called **My Company** is `my-company`.

{% hint style="info" %}
As slugs are uniques, if several domains have the same name, their slugs will be different (e.g. `uccello`, `uccello-1`).
{% endhint %}

When a domain is renamed, its slug is automatically regenerated.

## Multi-domain or not?

Multi-domain management is **enabled by default** in Uccello, but it can be easily disabled to meet the needs of small projects.

To **disable** multi-domain management, add the following to the `.env` file of your application:

```
UCCELLO_MULTI_DOMAINS=false
```

{% hint style="warning" %}
After each activation or deactivation of the multi-domain management, remember to clear the cache:

```bash
php artisan cache:clear
php artisan route:clear # only if you cache the routes
```

{% endhint %}

### With multi-domain

#### Routes

When multi-domain is enabled, all the [default routes](https://uccello.gitbook.io/doc/the-basics/routes#default-routes) contains the current domain's slug.

```
/uccello/user/detail?id=1
/acme/person/list
/aguapassion/invitation/edit
```

The **advantages** of using the domain's slug in the URL are:&#x20;

* You can easily share a URL and it will point to the right data in the right domain.
* You can easily work on different domains by opening several tabs in your browser.

#### Header

You can easily view the current domain name in the header.

![](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-LtjLkkuccWxXqXW22TU%2F-LtjSvv100J8n1caIWe_%2Fmulti-domain-header.png?alt=media\&token=4e7c3ce4-f4e8-4092-9eee-dde6f5e538b1)

By clicking on it, a modal opens and displays the domain tree. This allows you to easily switch to another domain.

![](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-LtjLkkuccWxXqXW22TU%2F-LtjT3MymCR0Ge9Y9tsu%2Fmulti-domain-modal.png?alt=media\&token=55f13ba7-bcf9-49d5-9fe3-e09067779e47)

#### Menu

The  **Security** submenu, available in the Settings Panel, display a link to access to the `domain` module.

![](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-LtjLkkuccWxXqXW22TU%2F-LtjU9GRJvzpYZYZkLlf%2Fmulti-domain-submenu.png?alt=media\&token=be0c137a-1bf8-4974-9b38-c26abb9cdbaa)

#### Descending view

Thanks to [Roles](https://uccello.gitbook.io/doc/security/role), you can allow user to activate **Descending view**. This option allows users to see data contained in the current domain and all its subdomains.

When multi-domain is enabled, if the user is authorized to do it, a button is displayed in the List View. By activating it, the user can view the data of the subdomains, in addition to the current domain.

{% hint style="info" %}
If the module contains a field called `domain` with the [Entity Uitype](https://uccello.gitbook.io/doc/uitypes-displaytypes/default-uitypes#entity) , the corresponding column is showed automatically in the List View when Descending view option is activated.
{% endhint %}

![](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-Ltj_GRPRkIJHH6hP6Rk%2F-Ltj_aii0JiGHFo3-2aP%2Fmulti-domain-descending-view.png?alt=media\&token=b81a00bf-c8b3-4292-8ee6-f3ca4621a05b)

### Without multi-domain

#### Routes

For projects that do not need a multi-domain, it can be cumbersome to have the domain slug that appears in all URLs. This is why when multi-domain management is disabled, no route contains the domain slug:

```
/user/detail?id=1
/person/list
/invitation/edit
```

{% hint style="info" %}
To facilitate management, if multi-domain management is disabled, Uccello assigns the data to the first active domain found in the database. So, if you decide to activate multi-domain management later, everything will work normally!
{% endhint %}

#### Header

When multi-domain is disabled, the header does not display the current domain and the modal for switching between domains.

![The current domain name is not displayed.](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-LtjX0ZVRf8y12OwXlWS%2F-LtjXFp-Byv5qzfUGFpw%2Fmono-domain-header.png?alt=media\&token=34921270-7c59-43b8-8ca1-a1c60d78b97a)

#### Menu

The  **Security** submenu, available in the Settings Panel, does not display link to access to the `domain` module.

![The Domains link is not displayed.](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-LtjX0ZVRf8y12OwXlWS%2F-LtjXR9NhfOLPjdCzZjn%2Fmono-domain-submenu.png?alt=media\&token=02c62a0a-32e0-4b11-b134-4d495f9f1f79)

#### Descending view

When multi-domain is disabled, the Descending view button is not displayed in the List View.

![The Descending View button is not displayed.](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-Ltj_ucJ5f-Ge9_P64RL%2F-Ltja9Roktdiyeh77uyC%2Fmono-domain-descending-view.png?alt=media\&token=0ec7f46e-45ee-46b7-9dec-c15250276468)

## Overpass domain filtering

Data filtering by domain is done automatically thanks to the Query Scope [inDomain](https://uccello.gitbook.io/doc/the-basics/scopes#indomain). This filter is activated if a `domain_id` column is present in the database table related to the module.

Sometimes it may be useful to create data that can be accessible across all domains, such as the list of countries for example. To do this, simply do not create a `domain_id` column in the database table related to the module. The Query Scope inDomain will then not be applied.
