karabinse/eloquent-searchable
Easily search eloquent models and their relations
Installation
You can install the package via composer:
composer require karabinse/eloquent-searchable
Usage
Add the trait and add columns that are searchable.
use Karabin\Searchable\Concerns\IsSearchable;
class User extends Authenticatable
{
use HasFactory, HasRoles, IsSearchable, Notifiable;
protected $searchable = [
'name',
'email',
'posts.title'
];
The package also includes a custom TermSearchFitler to be used with Laravel Query Builder.
use Karabin\Searchable\Filters\TermSearchFilter;
class UserController extends Controller
{
public function index(Request $request)
{
$users = QueryBuilder::for(User::class)
->allowedFilters([
AllowedFilter::custom('search', new TermSearchFilter),
])
->paginate($request->query('limit', 10));
return Inertia::render('User/Index', [
'users' => UserData::collect($users),
]);
}
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
651,963,193
9,701
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 1.4.3 | ^8.2 | ^9.0| | MIT | |
| 1.4.2 | ^8.2 | ^9.0| | MIT | |
| 1.4.1 | ^8.2 | ^9.0| | MIT | |
| 1.4.0 | ^8.2 | ^9.0| | MIT | |
| 1.3.0 | ^8.2 | ^10.0|| | MIT | |
| 1.2.1 | ^8.2 | ^10.0|| | MIT | |
| 1.2.0 | ^8.2 | ^10.0|| | MIT | |
| 1.1.0 | ^8.2 | ^10.0|| | MIT | |
| 1.0.1 | ^8.2 | ^10.0|| | MIT | |
| 1.0.0 | ^8.2 | ^10.0|| | MIT |