Skip to content

Custom Modules

Custom modules are a way to extend the functionality of your Evolve application. They can be used to encapsulate specific features, like a blog, a shop or a forum.

Setup

You can create a new Evolve module with the help of the evolve:module artisan command. Just provide a module name as vendor/package:

bash
php artisan evolve:module acme/blog

This command creates some module boilerplate inside modules/acme/blog and automatically registers it under the Acme\Blog namespace.

Registration

First, add the new service provider to your the providers array in config/app.php:

php
'providers' => [
    // ...
    \Acme\Blog\BlogServiceProvider::class,
    \Racerfish\Evolve\EvolveServiceProvider::class,
]

WARNING

Make sure the EvolveServiceProvider class is always last in order!

Then, use the Evolve Laravel Facade to register your new module inside the boot function of the service provider:

php
public function boot(): void
{
    parent::boot();

    Evolve::registerModule('blog', [
        'name' => 'Blog',
        'path' => $this->modulePath,
        // more configuration ...
    ]);
}

Adding CRUD resources

Evolve provides a evolve:resource helper command for creating CRUD resources inside your modules. You need to provide the package and resource name as arguments:

bash
php artisan evolve:resource acme/blog post

This command creates boilerplate code for a Acme\Blog\Post model with migrations, controllers, managers and backend views.

TIP

Add the -t or --translatable flag to also create I18n models and migrations of your resource.

Then, after setting up the migrations, run artisan:migrate to update your database schema.