LaravelPackages.net
Acme Inc.
Toggle sidebar
mawuekom/laravel-searchable

Laravel package to make easy search on Eloquent model

121
1
v1.2.0
About mawuekom/laravel-searchable

mawuekom/laravel-searchable is a Laravel package for laravel package to make easy search on eloquent model. It currently has 1 GitHub stars and 121 downloads on Packagist (latest version v1.2.0). Install it with composer require mawuekom/laravel-searchable. Discover more Laravel packages by mawuekom or browse all Laravel packages to compare alternatives.

Last updated

Laravel package to make easy search on Eloquent model

This package is provided with a service provider and trait to make search on your eloquent model

Installation

You can install the package via composer:

composer require mawuekom/laravel-searchable

Usage

Laravel

Go to config/app.php, and add this in the providers key

'providers' => [
    ...
    Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class,
    ...
]

Lumen

Go to bootstrap/app.php, and add this in the specified key

// Add provider 
$app->register(Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class);

Your model which inherits an eloquent model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    ...

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title',
        'content'
    ];

     ...
}

use App\Models\Post;

Post::whereLike(['title', 'content'], 'Post title');

You can also include Searchable Trait in your model.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mawuekom\LaravelSearchable\Searchable;

class Post extends Model
{
    use Searchable;

    ...
}

Once done, you can make your reseach like this


use App\Models\Post;

Post::search(['title', 'content'], 'Post title') ->get();

Once done, enjoy it.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security and Report bug

If you discover any security related issues, please email [email protected] or contact me on Twitter @ephraimseddor instead of using the issue tracker.

License

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

Star History Chart