# Overriding

Uccello was designed to make it very easy for developers to create applications that allow them to manage their data. However, it is quite possible to customize Uccello's behavior to meet specific needs.

For this purpose it is possible to override routes, controllers, views and translations.

## Override a View

It is extremely easy to override a view. If you create a blade file using the kernel directory architecture, Uccello will automatically detect your file and use it first. You can do this for all modules or for a particular module.

To override a view for a particular module, use this path: `resources/views/uccello/modules/`**`moduleName`**`/`**`viewName`**`/main.blade.php`

To override a view for all modules, use this path:

`resources/views/uccello/modules/default/`**`viewName`**`/main.blade.php`

{% hint style="info" %}
Here is the list of all default views name:

* index
* list
* detail
* edit
  {% endhint %}

{% hint style="warning" %}
It is only possible to override `main.blade.php` files. If you want to override other files, you can copy them from the kernel and adapt them in your application.
{% endhint %}

### Example 1

If you want to replace the home page, create the file `resources/views/uccello/modules/home/index/main.blade.php` with the following content:

{% tabs %}
{% tab title="resources/views/uccello/modules/home/index/main.blade.php" %}

```markup
@extends('uccello::modules.home.index.main')

@section('content')
<div class="row">
    <div class="col s12">
        This is my overrided home page!
    </div>
</div>
@endsection
```

{% endtab %}
{% endtabs %}

### Example 2

If you want to replace all index pages, create the file `resources/views/uccello/modules/default/index/main.blade.php` with the following content:

{% tabs %}
{% tab title="resources/views/uccello/modules/default/index/main.blade.php" %}

```markup
@extends('uccello::modules.default.index.main')

@section('content')
<div class="row">
    <div class="col s12">
        This is my overrided index page!
    </div>
</div>
@endsection
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
The overriding of a view from a specific module has priority over the overriding of a default view.
{% endhint %}

### Priority

To detect which view to use, Uccello uses the following priorities:

1. Module view overridden in app
2. Default view overridden in app
3. Module view overridden in package
4. Default view defined in package
5. Module view overridden in uccello
6. Default view defined in uccello
7. Fallback view if defined

## Override an Uitype

As with views, it is very easy to override a [uitype](https://uccello.gitbook.io/doc/uitypes-displaytypes/what-is-an-uitype).&#x20;

Each uitype can have its own HTML representation in the following views:

* Search field of the list view
* Cell of the table in the list view table
* Detail view
* Edit view

{% hint style="info" %}
You can view the list of default uitypes views, on the [Uccello Git repository](https://github.com/uccellolabs/uccello/tree/master/resources/views/modules/default/uitypes) or directly from your application in the following directory:`vendor/uccello/uccello/resources/views/modules/default/uitypes`
{% endhint %}

It is possible to override a uitype on a module level or for the entire application.

To override a uitype's view for a particular module, use this path: `resources/views/uccello/modules/`**`moduleName`**`/uitypes/`**`viewName`**`/`**`uitypeName`**`.blade.php`

To override a view for all modules, use this path:

`resources/views/uccello/modules/default/uitypes/`**`viewName`**`/`**`uitypeName`**`.blade.php`

{% hint style="info" %}
Here is the list of all default uitypes views name:

* search
* list
* detail
* edit
  {% endhint %}

{% hint style="warning" %}
If no views are defined for a specific uitype, Uccello uses by default the views defined for the `text` uitype.

For example, in a detail view, Uccello uses the file [resources/views/modules/default/uitypes/detail/text.blade.php](https://github.com/uccellolabs/uccello/blob/master/resources/views/modules/default/uitypes/detail/text.blade.php) to represent the `integer`uitype.
{% endhint %}

## Override a Controller

For override a Controller, you have to override 2 things:

* The controller of your choice
* The road to access this controller

### Controller

First of all you have to create a new controller which will extends the original one. For example you want to override the `DetailController` for the `user` module.

Create a file located at `app/Http/Controllers/User/DetailController.php` and add the following code:

```php
<?php

namespace App\Http\Controllers\User;

use Illuminate\Http\Request;
use Uccello\Core\Http\Controllers\Core\DetailController as UccelloDetailController;
use Uccello\Core\Models\Domain;
use Uccello\Core\Models\Module;

class DetailController extends UccelloDetailController
{
    /**
     * {@inheritdoc}
     */
    public function process(?Domain $domain, Module $module, Request $request)
    {
        // Get default view
        $view = parent::process($domain, $module, $request);

        // Useful if multi domains is not used
        $domain = $this->domain;

        // Get record
        $record = $this->getRecordFromRequest();

        // Your code here....

        // Add data to the view
        $view->myVariable = 'myValue';

        return $view;
    }
}
```

### Route

Modify the routes file located at `routes/web.php` and add the following code for overriding the route that points to the Detail View of the user module.

```php
<?php

...

// Adapt params if we use or not multi domains
if (!uccello()->useMultiDomains()) {
    $domainParam = '';
    $domainAndModuleParams = '{module}';
} else {
    $domainParam = '{domain}';
    $domainAndModuleParams = '{domain}/{module}';
}

Route::get($domainParam.'/user/detail', 'User\DetailController@process')
    ->defaults('module', 'user')
    ->middleware('uccello.permissions:retrieve')
    ->name('user.detail');
```

Now the route points to your overridden Controller.

## Override a Model

To override a Model you have to override 2 things:

* The model of your choice
* The module's `model_class` attribute in the database

### Model

Simply create a new model extending the original one, and put your overriding modification inside.

```php
<?php

namespace App;

use Uccello\Crm\Models\Role as UccelloRole;

class Role extends UccelloRole
{
    // Put your overriding modification here
}
```

### Attribute

Create a migration file and modify the `uccello_modules` table and change `model_class` attribute for using your new model.

```php
<?php

use Uccello\Crm\Models\Module;

// Inside your migration file:
$module = Module::where('name', 'role')->first();
$module->model_class = 'App\Role';
$module->save();
```

## Override a Localization file

It is very simple to override a Localization file from another package. To do this, just create a file located at `resources/lang/{lang_code}/{module_name}.php` and create a key for each translation label you want to override.

### Example

To override the `domain` module translation file in english, just create a file located at `resources/lang/en/domain.php` and add the following code:

```php
<?php

return [
    'domain' => 'Companies',
    'field' => [
        'name' => 'Company\'s name'
    ]
];
```

Now the `domain` module will be named **Companies** and the `name` field will be named **Company's name**.

![](https://1804066864-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LczzLgY9ndva4Lk64XC%2F-LtevcWKkHFni76tCdzF%2F-Ltevxu4anBd3V9C1qiI%2Foverride-translations.png?alt=media\&token=928294c7-7773-4e4f-9d04-1a6aaababfbf)
