{"id":281,"date":"2023-01-21T20:21:32","date_gmt":"2023-01-21T17:21:32","guid":{"rendered":"https:\/\/akaunting.com\/hc\/?post_type=docs&#038;p=281"},"modified":"2023-01-21T20:21:32","modified_gmt":"2023-01-21T17:21:32","slug":"search-string","status":"publish","type":"docs","link":"https:\/\/akaunting.com\/hc\/docs\/developers\/search-string\/","title":{"rendered":"Search String"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Akaunting uses the\u00a0<a href=\"https:\/\/github.com\/lorisleiva\/laravel-search-string\" target=\"_blank\" rel=\"noreferrer noopener\">lorisleiva\/laravel-search-string<\/a>\u00a0package in the backend to search\/filter records. Akaunting automatically prepares the frontend part. Follow these steps to implement them into your module.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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=\"91ddad0e6da3\">Create config file<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file under the\u00a0<code><a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/blob\/master\/Config\/search-string.php\" target=\"_blank\" rel=\"noreferrer noopener\">Config<\/a><\/code>\u00a0folder, which includes your models and their fields:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\nreturn [\n\n    'Modules\\MyBlog\\Models\\Post' => [\n        'columns' => [\n            'id',\n            'name' => ['searchable' => true],\n            'description' => ['searchable' => true],\n            'category_id' => [\n                'route' => ['categories.index', 'search=type:post'],\n            ],\n            'enabled' => ['boolean' => true],\n        ],\n    ],\n\n    'Modules\\MyBlog\\Models\\Comment' => [\n        'columns' => [\n            'id',\n            'description' => ['searchable' => true],\n            'post_id' => [\n                'route' => 'my-blog.posts.index',\n            ],\n        ],\n    ],\n\n];\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"128966d2b187\">Merge from provider<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The next step is to merge the config file of your module to Akaunting\u2019s&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/akaunting\/akaunting\/blob\/master\/config\/search-string.php\" target=\"_blank\">core<\/a>&nbsp;one. To do that, you should modify the&nbsp;<code><a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/blob\/master\/Providers\/Main.php#L83\" target=\"_blank\" rel=\"noreferrer noopener\">loadConfig<\/a><\/code>&nbsp;function of the provider:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">public function loadConfig()\n{\n    $merge_to_core_configs = ['search-string'];\n\n    foreach ($merge_to_core_configs as $config) {\n        Config::set($config, array_merge_recursive(\n            Config::get($config),\n            require __DIR__ . '\/..\/Config\/' . $config . '.php'\n        ));\n    }\n\n    $this-&gt;mergeConfigFrom(__DIR__ . '\/..\/Config\/my-blog.php', 'my-blog');\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"b506f1ed324f\">Add to blade<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The final step is to add the respective model into the&nbsp;<code><a href=\"https:\/\/github.com\/akaunting\/module-my-blog\/blob\/master\/Resources\/views\/posts\/index.blade.php#L42\" 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","protected":false},"excerpt":{"rendered":"<p>Akaunting uses the\u00a0lorisleiva\/laravel-search-string\u00a0package in the backend to search\/filter records. Akaunting automatically prepares the frontend part. Follow these steps to implement them into your module. Feel free to check out the&nbsp;My Blog&nbsp;module for the full example. Create config file Create a file under the\u00a0Config\u00a0folder, which includes your models and their fields: Merge from provider The next [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":31,"menu_order":8,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-281","docs","type-docs","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/281","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=281"}],"version-history":[{"count":1,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/281\/revisions"}],"predecessor-version":[{"id":282,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/docs\/281\/revisions\/282"}],"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=281"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/akaunting.com\/hc\/wp-json\/wp\/v2\/doc_tag?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}