chrisreedio/laravel-scout-keys

Provides user level tenant tokens / scoped search keys.

v1.0.0-beta.4 2024-09-18 19:14 UTC

This package is auto-updated.

Last update: 2024-09-18 19:15:48 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides user level tenant tokens / scoped search keys for Laravel Scout.

The current implementation supports the Meilisearch and Typesense drivers.

TODO

  • Add support for runtime configuration of generated key facets/filtered attributes

Installation

You can install the package via composer:

composer require chrisreedio/laravel-scout-keys

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-scout-keys-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-scout-keys-config"

This is the contents of the published config file:

return [
     /**
     * Whether to register the Scout Indexing commands for use via web.
     */
    'register_commands' => false,

    'key' => [
        /**
         * The number of minutes a search key should be valid for.
         */
        'lifetime' => env('SCOUT_KEY_EXPIRATION', 60 * 12),
    ],
];

Usage

Add the SearchUser interface and HasSearchKeys trait to your User model(s).

Example:

class User extends Authenticatable SearchUser
{
    use HasFactory, HasSearchKeys;
    // ...
}

Finally, add the following to your web.php routes file:

ScoutKeys::getRoute();

If you'd like to change the default path of /search/key, you may pass the desired path as the first argument to the getRoute method.

ScoutKeys::getRoute('dashboard/search/key');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.