Making a module for Akaunting (sponsor)


April 20th, 2020


Akaunting is an online, open-source, and free accounting software designed for small businesses and freelancers. It is built with modern technologies such as Laravel, VueJS, Bootstrap 4, RESTful API, etc. From invoicing to expense tracking to accounting, Akaunting has all the basic tools needed to manage money online. For further features, instead of creating a bloated software by adding all of them to the core, we’ve created a modular structure so that it could get extended easily.

Akaunting provides an awesome App Store for users and creates an income channel for Laravel developers all around the world. A module is like a Laravel package, it has some routes, views, controllers, and models. While technically we call it Module, we name it App in the UI for the end-user as that’s what they are familiar with.

So let’s make the first module together:

Install Akaunting

First of all, let’s install Akaunting in 3 basic steps:

  • Clone the repository: git clone
  • Install dependencies: composer install ; npm install ; npm run dev
  • Install Akaunting:
1php artisan install --db-name="akaunting" --db-username="root" --db-password="pass" --admin-email="" --admin-password="123456"
  • Create sample data (optional): php artisan sample-data:seed

Make a module

The akaunting/module package is used as builder. There are loads of Artisan commands built-in the package. For example, let’s make a new module:

1php artisan module:make my-blog

This will create all files and folders. Now let’s install the module:

1php artisan module:install my-blog 1

my-blog is the alias of the module and 1 is the company id that you want to install the module. Here you can find more about companies in Akaunting.

Alias is the slug/unique of the module as is used everywhere in Akaunting.

Folder Structure

As you can see from the example below, the structure of a module is very similar to a basic Laravel app.

6 ├── MyBlog/
7 ├── Console/
8 ├── Database/
9 ├── Migrations/
10 ├── Seeds/
11 ├── Http/
12 ├── Controllers/
13 ├── Requests/
14 ├── Jobs/
15 ├── Listeners/
16 ├── Models/
17 ├── Providers/
18 ├── Main.php
19 ├── Resources/
20 ├── assets/
21 ├── lang/
22 ├── views/
23 ├── Routes/
24 ├── admin.php
25 ├── portal.php
26 ├── composer.json
27 ├── module.json
28 ├── package.json
29 ├── webpack.mix.js

module.json file

The module.json file contains the main information about your module such as name, version, providers, etc..

2 "alias": "my-blog",
3 "icon": "fas fa-pen",
4 "version": "1.0.0",
5 "category": "accounting",
6 "active": 1,
7 "providers": [
8 "Modules\\MyBlog\\Providers\\Main"
9 ],
10 "aliases": {},
11 "files": [],
12 "requires": [],
13 "reports": [],
14 "widgets": [],
15 "settings": []

Adding module to left sidebar/menu

You may want to extend the menu by adding your own pages. In such a case, you can listen to the AdminCreated event for admin and/or PortalCreated for client sides.

Let’s firstly create the listener:

3namespace Modules\MyBlog\Listeners;
5use App\Events\Menu\AdminCreated as Event;
7class AddMenu
9 /**
10 * Handle the event.
11 *
12 * @param Event $event
13 * @return void
14 */
15 public function handle(Event $event)
16 {
17 // Add child to existing menu item
18 $item = $event->menu->whereTitle(trans_choice('general.sales', 2));
19 $item->url('my-blog/posts', 'Posts', 4, ['icon' => '']);
21 // Add new menu item
22 $event->menu->add([
23 'url' => 'my-blog/posts',
24 'title' => 'Posts',
25 'icon' => 'fas fa-pen',
26 'order' => 5,
27 ]);
28 }

Then add your listener into the $listen array of your Modules\MyBlog\Providers\Event service provider:

1'App\Events\Menu\AdminCreated' => [
2 'Modules\MyBlog\Listeners\AddMenu',

Menu documentation can help to understand the system, especially about how to find a menu item, add child ones, and create dropdown menus.

Settings page

Akaunting ships with a centralized settings page where modules can add their own in a few steps. Mostly, developers just want to add just some inputs on the settings page. In such a case, you can add them to the module.json file and Akaunting will display your module under the Settings page, nothing else is required.

All you have to do is to fill the settings array like the following:

1"settings": [
2 {
3 "type": "textGroup",
4 "name": "title",
5 "title": "my-blog::general.title",
6 "icon": "font",
7 "attributes": {
8 "required": "required"
9 },
10 "rules": "required|string"
11 },
12 {
13 "type": "textGroup",
14 "name": "header",
15 "title": "my-blog::general.description",
16 "icon": "user",
17 "attributes": {},
18 "rules": "nullable|string"
19 }

If your settings page needs a little bit more actions then you can check this article.

Go go go

Now you’re ready to go to the Main controller and start writing the code you want just like in a basic Laravel app. For sure that there are more to learn about Akaunting module development such as overriding output, hooking models, handling permissions, and a lot more.

Start today

As you can see it’s easy peasy to make a module for Akaunting and create a new income channel. Join a strong community of accounting innovators and gain access to the fastest-growing accounting SMB base.

Finally, don’t forget to check our GitHub repository. Pull requests are more than welcome :-)

Filed in:

Eric L. Barnes

Eric is the creator of Laravel News and has been covering Laravel since 2012.