PHP code example of ahmetbarut / laravel-full-search

1. Go to this page and download the library: Download ahmetbarut/laravel-full-search library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ahmetbarut / laravel-full-search example snippets


    // config/fullsearch.php
use App\Models\Post;

return [
    'models' => [
        Post::class => [
            'searchable' => true,
            'ability' => false, // false or middleware name example: auth => 'auth',
            'searchable_fields' => [
                'title',
                'body',
                'id',
            ],
            'response_parameters' => [
                'title' => 'title',
                'page' => 'Posts',
            ],
            'route' => [
                'name' => 'post',
                'parameters' => [
                    'post' => 'id',
                ],
            ],
            'max_results' => 10,
        ],
    ],
];

    // app/Providers/AuthServiceProvider.php
use Illuminate\Support\Facades\Gate;

    public function boot()
    {
        $this->registerPolicies();

        Gate::define('admin', function ($user) {
            return $user->isAdmin();
        });
    }

    // config/fullsearch.php
use App\Models\User;

return [
    'models' => [
        User::class => [
            'searchable' => true,
            'ability' => 'admin',
            'searchable_fields' => [
                'name',
                'email',
                'id',
            ],
            'response_parameters' => [
                'name' => 'name',
                'page' => 'Users',
            ],
            'route' => [
                'name' => 'user',
                'parameters' => [
                    'user' => 'id',
                ],
            ],
            'max_results' => 10,
        ],
    ],
];

    // config/fullsearch.php
    'searchable_fields' => [
        'name',
        'email',
        'id',
    ],
    'response_parameters' => [
-       'name' => 'name',
+       'name' => 'email',
        'page' => 'Users',
    ],

...
        // config/fullsearch.php
    'searchable_fields' => [
        'name',
        'email',
        'id',
    ],
    'route' => [
        'name' => 'user',
        'parameters' => [
-           'user' => 'id',
+           'user' => 'email',
        ],
    ],
...
shell
    php artisan vendor:publish --provider="AhmetBarut\\LaravelFullSearch\\Providers\\LaravelFullSearchServiceProvider" --tag="fullsearch-config"