technote / laravel-search-helper
Search helper for laravel
Fund package maintenance!
paypal.me/technote0space
Installs: 5 545
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 5
Requires
- php: ^7.4|^8.0
- laravel/framework: *
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.32.0
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.2
- fakerphp/faker: ^1.19
- orchestra/testbench: ^6.24
- phpmd/phpmd: ^2.12
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- dev-main
- v0.2.28
- v0.2.27
- v0.2.26
- v0.2.25
- v0.2.24
- v0.2.23
- v0.2.22
- v0.2.21
- v0.2.20
- v0.2.19
- v0.2.18
- v0.2.17
- v0.2.16
- v0.2.15
- v0.2.14
- v0.2.13
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-dependabot/composer/symfony/http-kernel-5.4.25
- dev-dependabot/composer/phpunit/phpunit-9.5.8
- dev-dependabot/composer/codedungeon/phpunit-result-printer-0.31.0
- dev-dependabot/composer/phpmd/phpmd-2.10.2
- dev-dependabot/composer/fakerphp/faker-1.15.0
- dev-dependabot/composer/orchestra/testbench-6.19.0
- dev-dependabot/composer/league/flysystem-1.1.4
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/laravel/framework-7.30.0
This package is auto-updated.
Last update: 2024-11-22 17:08:23 UTC
README
Read this in other languages: English, 日本語.
Search helper for Laravel.
Table of Contents
Install
composer require technote/laravel-search-helper
Usage
-
Implement
Searchable Contract
andSearchable Trait
. -
Implement
setConditions
method.<?php namespace App\Models; use Eloquent; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Technote\SearchHelper\Models\Contracts\Searchable as SearchableContract; use Technote\SearchHelper\Models\Traits\Searchable; /** * Class Item * @mixin Eloquent */ class Item extends Model implements SearchableContract { use Searchable; /** * @var array */ protected $guarded = [ 'id', ]; /** * @param Builder $query * @param array $conditions */ protected static function setConditions(Builder $query, array $conditions) { if (! empty($conditions['s'])) { collect($conditions['s'])->each(function ($search) use ($query) { $query->where(function ($builder) use ($search) { /** @var Builder $builder */ $builder->where('items.name', 'like', "%{$search}%"); }); }); } } }
-
Call
search
method.<?php use App\Models\Item; Item::search([ 's' => [ 'test', ], 'ids' => [1, 2, 3], ])->get();