hetparekh21/searchable

Add simple search functionality to any model

1.0.0 2024-01-11 07:12 UTC

This package is auto-updated.

Last update: 2024-09-30 07:11:55 UTC


README

Effortlessly add search functionality to your Laravel models.

Installation

  1. Install the package via Composer:
composer require hetparekh21/searchable

Usage

  1. Use the Searchable trait in your model:
use hetparekh21\searchable\Searchable;

class User extends Model
{
    use Searchable;

    protected $fillable = [
        'first_name',
        'last_name',
        'email',
        'phone'
    ];

    protected $guarded = ['id'];

    protected $except = ['phone'];

    protected $useGuarded = false;

}
  1. Perform searches using the scopeSearch method:
$users = User::search('John Doe')->get();
  1. Search Paginated, As easy as laravel default queries
$users = User::search('John Doe')->paginate(10);

Configuration

  • except property: Exclude specific columns from the search (optional).
  • useGuarded property: Include guarded attributes in the search (optional).

Contributing

Anyone is welcome to contribute. Fork, make your changes, and then submit a pull request.

License

Searchable is open-sourced software licensed under the MIT license: LICENSE.