Skip to content

Extending Evolve

Thanks to some concepts in Laravel like the Dependency Injection or the Blade View Loader most parts of Evolve can easily be extended and overridden.

Disclaimer

Be aware that Evolve updates can break your extensions. You are responsible for keeping your custom implementaions in sync with changes inside the Evolve Core or any Evolve package.

Overriding Views

You can override Blade views from inside vendor packages by coping them into your application's resources/views/vendor/[packageName] directory.

So, using the Blog package as an example, Laravel will first check if a custom version of the view has been placed in the resources/views/vendor/blog directory before loading it from the composer's vendor directory.

Read more in the official Laravel docs: Overriding Package Views

WARNING

Make sure the relative view path inside the package is identical to the original package inside composer's vendor directory.

Extending Models and Controllers

Models, Controllers or any other PHP class can easily be extended or completely swapped out using Laravel's powerful Service Container concept.

Again, using the Blog package as an example, if you want to extend or replace the Post model, you can create a custom version of the model in your projects app/Models directory (or anywhere you like) and extend the original.

php
<?php
namespace App\Models;

class Post extends \Racerfish\Blog\Models\Post {
    // custom logic
}

Now you need to tell Laravel's Service Container to use your custom class when resolving the Post model. You can do this with a simple container binding or use our little Extension helper class.

php
use Racerfish\Evolve\Services\Extension;

public function register()
{
    // Swap original class with our custom implementation
    Extension::swap([
        \Racerfish\Blog\Models\Post::class => \App\Models\Post::class,
    ]);
}