sqits/laravel-searchable

Package to add an easy way to add a basic search functionality to your models

dev-main 2021-07-07 06:43 UTC

This package is auto-updated.

Last update: 2024-05-07 12:42:48 UTC


README

Provides an Eloquent trait to add to your models to integrate an easy way to search in your model and relations.

Latest Version on Packagist Build Status Quality Score StyleCI Total Downloads

Installation and usage

This package requires PHP 7.3 and Laravel 5.6 or higher. Install the package by running the following command in your console;

composer require sqits/laravel-searchable

You can publish the config file with:

php artisan vendor:publish --provider="Sqits\Searchable\SearchableServiceProvider" --tag="config"

This is the contents of the published config file:

return [

    /*
     * Define the parameter in your request which contains the search values
     */

    'parameter' => 'search',

];

Add the Trait to your model

use Sqits\Searchable\Traits\HasSearchable;

class Example extends Model {

    use HasSearchable;
}

Add the configuration to your model which fields are searchable

// In the examples we are using `like`, but every value which you could use in eloquent are usable eg '=', '=>', '<=', '>', '<' etc.

// simple field
protected $searchables = [
    'name' => 'like',
];

// combined fields
protected $searchables = [
    'name' => [
        'first_name' => 'like',
        'last_name' => 'like',
    ],
];

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security-related issues, please email to info@sqits.nl instead of using the issue tracker.

Credits

upda

License

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