Overriding Package Functionality
Nexus is designed to make it as easy as possible to customise functionality provided by packages.
However, the more you override the harder it is to upgrade/maintain. So before you start, please talk to a senior developer about whether this is the right solution (perhaps the functionality you need could be added to the base package instead).
Note: Some packages (e.g. the CMS block editor) are specifically designed to allow this, while others may not be.
PHP Classes (Models, Controllers, etc.)
Create a new class that extends the original, replacing the Alberon\ namespace with App\. For example, to override Alberon\NexusUsers\Models\User:
<?php
namespace App\NexusUsers\Models;
use Alberon\NexusUsers\Models\User as NexusUser;
class User extends NexusUser
{
// ...
}
Then add a custom binding to app/Providers/NexusServiceProvider.php, e.g.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class NexusServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(
\Alberon\NexusUsers\Models\User::class,
\App\NexusUsers\Models\User::class,
);
}
}
If this doesn't work as expected, make sure the package uses app(Example::class) rather than referring to the class directly, and talk to Dave if you're not sure how to resolve it.
Vue Components (Including Pages) and Other JS/CSS Files
Create a new file in resources/<package>/<filename>. For example, resources/nexus-demo/vue/PageDemo.vue.
Note: You may need to stop and restart Webpack after creating the file, as it caches the paths. If this doesn't work as expected, make sure the import uses @alberon/<package>/... rather than a relative path.
The simplest way to override something is to copy/paste it into the new file. However, if you want to refer to the original component/script, you must use a relative path to prevent recursion. For example:
<script>
import BaseComponent from '../../../vendor/alberon/nexus-demo/assets/vue/PageDemo';
export default {
extends: BaseComponent,
// ...
}
</script>
Blade Views
To override a Blade view, create a file in resources/<package>/views/<name>.blade.php. For example, to override nexus::app (vendor/alberon/nexus/views/app.blade.php), create a replacement file in resources/nexus/app.blade.php.
Reminder: A . in a view name is replaced with a / in the filename - e.g. nexus::layouts._head would become resources/nexus/layouts/_head.blade.php.