Search String

Akaunting uses the lorisleiva/laravel-search-string package in the backend to search/filter records. The frontend part is automatically prepared by Akaunting. Follow these steps to implement into your module.

Feel free to check out the My Blog module for the full example.

Create config file

Create a file under the Config folder which includes your models and their fields:

<?php

return [

    'Modules\MyBlog\Models\Post' => [
        'columns' => [
            'id',
            'name' => ['searchable' => true],
            'description' => ['searchable' => true],
            'category_id' => [
                'route' => ['categories.index', 'search=type:post'],
            ],
            'enabled' => ['boolean' => true],
        ],
    ],

    'Modules\MyBlog\Models\Comment' => [
        'columns' => [
            'id',
            'description' => ['searchable' => true],
            'post_id' => [
                'route' => 'my-blog.posts.index',
            ],
        ],
    ],

];

Merge from provider

The next step is to merge the config file of your module to Akaunting’s core one. To do that, you should modify the loadConfig function of the provider:

public function loadConfig()
{
    $merge_to_core_configs = ['search-string'];

    foreach ($merge_to_core_configs as $config) {
        Config::set($config, array_merge_recursive(
            Config::get($config),
            require __DIR__ . '/../Config/' . $config . '.php'
        ));
    }

    $this->mergeConfigFrom(__DIR__ . '/../Config/my-blog.php', 'my-blog');
}

Add to blade

The final step is to add the respective model into the index.blade.php file:

<div class="align-items-center" v-if="!bulk_action.show">
    <x-search-string model="Modules\MyBlog\Models\Post" />
</div>
Scroll to top