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, in order 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 ServiceProvider
. Here 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
{
/**
* Bind data to the view.
*
* @param View $view
* @return mixed
*/
public function compose(View $view)
{
// 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, then you can create an Observer to hook models.