hetparekh21/searchable

为任何模型添加简单的搜索功能

1.0.0 2024-01-11 07:12 UTC

This package is auto-updated.

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


README

轻松为您的Laravel模型添加搜索功能。

安装

  1. 通过Composer安装此包
composer require hetparekh21/searchable

用法

  1. 在模型中使用Searchable特性
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. 使用scopeSearch方法执行搜索
$users = User::search('John Doe')->get();
  1. 搜索分页,和Laravel默认查询一样简单
$users = User::search('John Doe')->paginate(10);

配置

  • except属性:从搜索中排除特定的列(可选)。
  • useGuarded属性:在搜索中包含受保护的属性(可选)。

贡献

任何人都可以进行贡献。Fork,进行修改,然后提交一个pull request。

许可证

Searchable是开源软件,受MIT许可证的许可:LICENSE。