Overriding Output

Estimated reading: 2 minutes

Let’s say you’re developing a module/app that adds/removes functionality to/from Akaunting core, and you want to override the output. However, to keep Akaunting up-to-date, you don’t want to, and shouldn’t, change/hack the core files. As an example, let’s see how to remove the Phone field from the customer creation form without changing the core files.

First of all, create and install a module.

Then add the following code into the boot method of your ServiceProviderHere you can learn more about view composers.

View::composer(
    ['incomes.customers.create'], 'Modules\MyBlog\Http\ViewComposers\Customers'
);

Then create the view composer file:

<?php

namespace Modules\MyBlog\Http\ViewComposers;

use Illuminate\View\View;

class Customers
{
    public function compose(View $view): mixed
    {
        // Override just the 'content' section
        $view->getFactory()->startSection('content', view('my-blog::customers.create'));

        // Override the whole file
        $view->setPath(view('my-blog::customers.create')->getPath());

        // Push to a stack
        $view->getFactory()->startPush('scripts', view('my-blog::script'));
    }
}

Finally, create a Blade template file modules/MyBlog/Resources/views/customers/create.blade.php with your custom output. The original one is located in resources/views/incomes/customers/create.blade.php file.

If you also want to modify the data stored in the database, you can create an Observer to hook models.

Share this Doc

Overriding Output

Or copy link

CONTENTS