{"id":291,"date":"2023-01-21T20:35:22","date_gmt":"2023-01-21T17:35:22","guid":{"rendered":"https:\/\/akaunting.com\/hc\/?post_type=docs&#038;p=291"},"modified":"2023-01-21T20:36:15","modified_gmt":"2023-01-21T17:36:15","slug":"beyond-crud","status":"publish","type":"docs","link":"https:\/\/akaunting.com\/hc\/docs\/developers\/beyond-crud\/","title":{"rendered":"Beyond CRUD"},"content":{"rendered":"\n<p>In this article you\u2019ll learn how to make a&nbsp;<strong>Blog<\/strong>&nbsp;module with beyond CRUD functions for admin and shown in the client portal.<\/p>\n\n\n\n<p><code>my-blog<\/code>\u00a0is the alias aka unique identifier of the\u00a0<a href=\"https:\/\/akaunting.com\/hc\/docs\/developers\/modules\/\" target=\"_blank\" rel=\"noreferrer noopener\">module<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"a91cfcaac57f\">Download<\/h3>\n\n\n\n<p>You can get the ready-to-use files from&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/akaunting\/module-my-blog\" target=\"_blank\">GitHub<\/a>&nbsp;or apply the following steps to create the same module.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"c34715c52eb3\">Scaffold<\/h3>\n\n\n\n<p>First of all, generate the scaffold by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">php artisan module:make my-blog<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8990f8a3a4d2\">Migrations<\/h3>\n\n\n\n<p>Before installing the module, create the database tables:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">php artisan module:make-migration my_blog_v1 my-blog<\/code><\/pre>\n\n\n\n<p>The command will create the&nbsp;<a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/blob\/master\/Database\/Migrations\/2021_06_30_000000_my_blog_v1.php\" target=\"_blank\" rel=\"noreferrer noopener\">migration<\/a>&nbsp;file into&nbsp;<code>modules\/MyBlog\/Database\/Migrations<\/code>&nbsp;folder.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"b5ec1414b8a1\">Installation<\/h3>\n\n\n\n<p>Now you can install the module. Akaunting will also run the migrations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">php artisan module:install my-blog 1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bad3793dc3dc\">Model<\/h3>\n\n\n\n<p>Create the&nbsp;<a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/tree\/master\/Models\" target=\"_blank\" rel=\"noreferrer noopener\">model<\/a>&nbsp;by using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">php artisan module:make-model Post my-blog --fillable=company_id,name,description,category_id,enabled,created_by<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"d30669135d59\">Routes<\/h3>\n\n\n\n<p>The scaffold comes with 2&nbsp;<a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/tree\/master\/Routes\" target=\"_blank\" rel=\"noreferrer noopener\">route files<\/a>. Add the controllers for both admin and portal.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"38ef73ec24fb\">Controllers<\/h3>\n\n\n\n<p>By default, a&nbsp;<code>Main<\/code>&nbsp;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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">php artisan module:make-controller Posts my-blog\nphp artisan module:make-controller Portal\\Posts my-blog<\/code><\/pre>\n\n\n\n<p>You should also add the new controllers to the\u00a0<code>FinishInstallation<\/code>\u00a0<a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/blob\/master\/Listeners\/FinishInstallation.php#L32\" target=\"_blank\" rel=\"noreferrer noopener\">listener<\/a>\u00a0as mentioned in the\u00a0<a href=\"https:\/\/akaunting.com\/hc\/docs\/developers\/permissions\/\" target=\"_blank\" rel=\"noreferrer noopener\">Permissions<\/a>\u00a0article.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"c812d1449feb\">Jobs<\/h3>\n\n\n\n<p>Akaunting uses the&nbsp;<strong>Job<\/strong>&nbsp;kind of action to&nbsp;<code>Create<\/code>,&nbsp;<code>Update<\/code>, and&nbsp;<code>Delete<\/code>&nbsp;records. It makes that code re-usable in other places such as API, console, etc.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">php artisan module:make-job CreatePost my-blog --sync\nphp artisan module:make-job UpdatePost my-blog --sync\nphp artisan module:make-job DeletePost my-blog --sync<\/code><\/pre>\n\n\n\n<p>Check out the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/akaunting\/akaunting\/blob\/master\/app\/Jobs\/Common\/CreateItem.php\" target=\"_blank\">CreateItem<\/a>&nbsp;or&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/akaunting\/akaunting\/blob\/master\/app\/Jobs\/Common\/DeleteCompany.php\" target=\"_blank\">DeleteCompany<\/a>&nbsp;jobs for real-life examples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ee6fbe0784bd\">Search String<\/h3>\n\n\n\n<p>Akaunting uses the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/lorisleiva\/laravel-search-string\" target=\"_blank\">Search String<\/a>&nbsp;package in the backend to search and filter the records. To make the module compatible, create a&nbsp;<code>search-string.php<\/code>&nbsp;config file referring to the model, merge it to the core config in the service provider, and put a couple of lines in the&nbsp;<code>index.blade.php<\/code>&nbsp;file, Akaunting will do the frontend magic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"b4bed6d3bdac\">Menu<\/h3>\n\n\n\n<p>In order to show the blog in the menu (left sidebar), you should listen to the&nbsp;<code>AdminCreated<\/code>&nbsp;and&nbsp;<code>PortalCreated<\/code>&nbsp;events, separately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"b4e1ea5e03a0\">Language<\/h3>\n\n\n\n<p>The language file is&nbsp;<code>Resources\/lang\/en-GB\/general.php<\/code>&nbsp;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article you\u2019ll learn how to make a&nbsp;Blog&nbsp;module with beyond CRUD functions for admin and shown in the client portal. my-blog\u00a0is the alias aka unique identifier of the\u00a0module. Download You can get the ready-to-use files from&nbsp;GitHub&nbsp;or apply the following steps to create the same module. Scaffold First of all, generate the scaffold by running [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":31,"menu_order":12,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-291","docs","type-docs","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/comments?post=291"}],"version-history":[{"count":2,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/291\/revisions"}],"predecessor-version":[{"id":293,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/291\/revisions\/293"}],"up":[{"embeddable":true,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/31"}],"wp:attachment":[{"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/media?parent=291"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/doc_tag?post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}