Beyond CRUD

Estimated reading: 3 minutes

In this article you’ll learn how to make a Blog module with beyond CRUD functions for admin and shown in the client portal.

my-blog is the alias aka unique identifier of the module.

Download

You can get the ready-to-use files from GitHub or apply the following steps to create the same module.

Scaffold

First of all, generate the scaffold by running the following command:

php artisan module:make my-blog

Migrations

Before installing the module, create the database tables:

php artisan module:make-migration my_blog_v1 my-blog

The command will create the migration file into modules/MyBlog/Database/Migrations folder.

Installation

Now you can install the module. Akaunting will also run the migrations.

php artisan module:install my-blog 1

Model

Create the model by using the following command:

php artisan module:make-model Post my-blog --fillable=company_id,name,description,category_id,enabled,created_by

Routes

The scaffold comes with 2 route files. Add the controllers for both admin and portal.

Controllers

By default, a Main controller is automatically created when you make a module. However, in this case, you need a separate controller for admin and another one for portal. So create them using the following commands:

php artisan module:make-controller Posts my-blog
php artisan module:make-controller Portal\Posts my-blog

You should also add the new controllers to the FinishInstallation listener as mentioned in the Permissions article.

Jobs

Akaunting uses the Job kind of action to CreateUpdate, and Delete records. It makes that code re-usable in other places such as API, console, etc.

php artisan module:make-job CreatePost my-blog --sync
php artisan module:make-job UpdatePost my-blog --sync
php artisan module:make-job DeletePost my-blog --sync

Check out the CreateItem or DeleteCompany jobs for real-life examples.

Search String

Akaunting uses the Search String package in the backend to search and filter the records. To make the module compatible, create a search-string.php config file referring to the model, merge it to the core config in the service provider, and put a couple of lines in the index.blade.php file, Akaunting will do the frontend magic.

Menu

In order to show the blog in the menu (left sidebar), you should listen to the AdminCreated and PortalCreated events, separately.

Language

The language file is Resources/lang/en-GB/general.php .

Share this Doc

Beyond CRUD

Or copy link

CONTENTS