Search String

Estimated reading: 2 minutes

Akaunting uses the lorisleiva/laravel-search-string package 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 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:

<x-index.search
    search-string="Modules\MyBlog\Models\Post"
    bulk-action="Modules\MyBlog\BulkActions\Posts"
/>
Share this Doc

Search String

Or copy link

CONTENTS