dvsoftsrl/eloquent-searchable

Your Package Description here

1.0.0 2022-05-13 10:27 UTC

This package is auto-updated.

Last update: 2024-10-27 17:59:50 UTC


README

Packagist Version GitHub Workflow Status Software License Total Downloads

Install

composer require dvsoftsrl/eloquent-searchable

Usage

Eloquent Model

For using uuid in your Eloquent Model, just put use EloquentSearchableTrait;:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DvSoft\EloquentSearchable\EloquentSearchableTrait;

class Post extends Model
{
    use EloquentSearchableTrait;
    
    // You can specify the columns to search on
    protected $searchable = ['tile', 'excerpt'];
}

Search:

After that, you can search on your model:

    $posts = Post::search($query)->get();

You can use it with every other eloquent methods

    $posts = Post::where('published', true)->search($query)->paginate();

You can require that the search query match all fields by adding true at second parameter:

    $posts = Post::search($query, true)->get();

Testing

Run the tests with:

vendor/bin/phpunit

Security

If you discover any security-related issues, please email developers@dvsoft.it instead of using the issue tracker.

Credits

License

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