定制 jochemict/larasearch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jochemict/larasearch

最新稳定版本:v1.1.9

Composer 安装命令:

composer require jochemict/larasearch

包简介

A simple and efficient Laravel package that adds flexible, reusable search functionality to your Eloquent models.

README 文档

README

Larasearch is a lightweight and efficient Laravel package that adds reusable multi-column search functionality to your Eloquent models. It simplifies search logic by letting you define searchable attributes directly inside your models, keeping your controllers clean and your code DRY.

Features

  • Easily add multi-column search to any Eloquent model
  • Define searchable fields once per model
  • Simple query scope for quick integration
  • Clean, reusable, and centralized search logic
  • Lightweight with minimal dependencies
  • Compatible with Laravel 8, 9, and 10

Installation

Install Larasearch via Composer:

composer require jochemict/larasearch

Usage

  1. Add the Larasearchable trait to your model
use JochemICT\Larasearch\Larasearchable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Larasearchable;

    /**
     * The attributes that are searchable via Larasearch.
     *
     * @var array
     */
    protected $searchable = ['name', 'email', 'city'];
}
  1. Use the search scope in your queries
public function index(Request $request)
{
    $searchTerm = $request->input('search');

    $users = User::search($searchTerm)->get();

    return view('users.index', compact('users'));
}

Examples

Search with pagination

$users = User::search($request->input('search'))->paginate(15);

Combine search with other query constraints

$users = User::where('active', true)
             ->search($request->input('search'))
             ->get();

Return all results if no search term is provided

$users = User::search(null)->get(); // returns all users

Requirements

  • PHP 7.4 or higher
  • Laravel 8.x, 9.x, or 10.x
  • Illuminate/database (included with Laravel)

Contributing

Contributions and feature requests are welcome! Please open an issue or submit a pull request on the GitHub repository.

License

Licensed under the MIT License. See the LICENSE file for details.

Contact

Created by JochemICT
GitHub Email

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-17