{"id":279,"date":"2023-01-21T20:17:31","date_gmt":"2023-01-21T17:17:31","guid":{"rendered":"https:\/\/akaunting.com\/hc\/?post_type=docs&#038;p=279"},"modified":"2023-01-21T20:17:31","modified_gmt":"2023-01-21T17:17:31","slug":"bulk-actions","status":"publish","type":"docs","link":"https:\/\/akaunting.com\/hc\/docs\/developers\/bulk-actions\/","title":{"rendered":"Bulk Actions"},"content":{"rendered":"\n<p>Bulk Actions allow users to check off multiple records, choose an action, and perform that action for all records simultaneously. You can implement Bulk Actions to your module in just 3 steps:<\/p>\n\n\n\n<p>Feel free to check out the&nbsp;<a href=\"https:\/\/github.com\/akaunting\/module-my-blog\" target=\"_blank\" rel=\"noreferrer noopener\">My Blog<\/a>&nbsp;module for the full example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"f2af2482fe7c\">Create the class<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\"><strong>&lt;?php<\/strong>\n\nnamespace Modules\\MyBlog\\BulkActions;\n\nuse App\\Abstracts\\BulkAction;\nuse Modules\\MyBlog\\Exports\\Posts as Export;\nuse Modules\\MyBlog\\Jobs\\DeletePost;\nuse Modules\\MyBlog\\Models\\Post;\n\nclass Posts extends BulkAction\n{\n    public $model = Post::class;\n\n    public $text = 'my-blog::general.posts';\n\n    public $path = [\n        'group' =&gt; 'my-blog',\n        'type' =&gt; 'posts',\n    ];\n\n    public $actions = [\n        'enable' =&gt; [\n            'name' =&gt; 'general.enable',\n            'message' =&gt; 'bulk_actions.message.enable',\n            'path' =&gt;  ['group' =&gt; 'my-blog', 'type' =&gt; 'posts'],\n            'permission' =&gt; 'update-my-blog-posts',\n        ],\n        'disable' =&gt; [\n            'name' =&gt; 'general.disable',\n            'message' =&gt; 'bulk_actions.message.disable',\n            'path' =&gt;  ['group' =&gt; 'my-blog', 'type' =&gt; 'posts'],\n            'permission' =&gt; 'update-my-blog-posts',\n        ],\n        'delete' =&gt; [\n            'name' =&gt; 'general.delete',\n            'message' =&gt; 'bulk_actions.message.delete',\n            'permission' =&gt; 'delete-my-blog-posts',\n        ],\n        'export' =&gt; [\n            'name' =&gt; 'general.export',\n            'message' =&gt; 'bulk_actions.message.export',\n            'type' =&gt; 'download',\n        ],\n    ];\n\n    public function destroy($request)\n    {\n        $posts = $this-&gt;getSelectedRecords($request, 'comments');\n\n        foreach ($posts as $post) {\n            try {\n                $this-&gt;dispatch(new DeletePost($post));\n            } catch (\\Exception $e) {\n                flash($e-&gt;getMessage())-&gt;error()-&gt;important();\n            }\n        }\n    }\n\n    public function export($request)\n    {\n        $selected = $this-&gt;getSelectedInput($request);\n\n        return $this-&gt;exportExcel(new Export($selected), trans_choice('my-blog::general.posts', 2));\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4b4c5a35e8b9\">Add to blade<\/h3>\n\n\n\n<p>Add the following line into the&nbsp;<code><a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/blob\/master\/Resources\/views\/posts\/index.blade.php#L43\" target=\"_blank\" rel=\"noreferrer noopener\">index.blade.php<\/a><\/code>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;x-index.search\n    search-string=\"Modules\\MyBlog\\Models\\Post\"\n    bulk-action=\"Modules\\MyBlog\\BulkActions\\Posts\"\n\/&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"78fca7af989c\">Add to vuejs<\/h3>\n\n\n\n<p>Finally, add the following line into the&nbsp;<code><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/akaunting\/module-my-blog\/blob\/master\/Resources\/assets\/js\/posts.js#L29\" target=\"_blank\">posts.js<\/a><\/code>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">bulk_action: new BulkAction('posts')<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Bulk Actions allow users to check off multiple records, choose an action, and perform that action for all records simultaneously. You can implement Bulk Actions to your module in just 3 steps: Feel free to check out the&nbsp;My Blog&nbsp;module for the full example. Create the class Add to blade Add the following line into the&nbsp;index.blade.php&nbsp;file: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":31,"menu_order":7,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-279","docs","type-docs","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/279","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=279"}],"version-history":[{"count":1,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/279\/revisions"}],"predecessor-version":[{"id":280,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/279\/revisions\/280"}],"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=279"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/doc_tag?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}