mawuekom / laravel-macro-search
Laravel 宏,用于在 Eloquent 模型上执行搜索
v1.0.1
2021-06-24 19:40 UTC
Requires
- php: ^7.4|^8.0
- illuminate/database: ^8.0
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
README
此包是一个宏服务提供程序,用于在您的 Eloquent 模型上执行搜索
安装
您可以通过 Composer 安装此包
composer require mawuekom/laravel-macro-search
用法
Laravel
转到 config/app.php,并在 providers 键中添加以下内容
'providers' => [ ... Mawuekom\MacroSearch\MacroSearchServiceProvider::class, ... ]
Lumen
转到 bootstrap/app.php,并在指定的键中添加以下内容
// Add provider $app->register(Mawuekom\MacroSearch\MacroSearchServiceProvider::class);
继承自 Eloquent 模型的您的模型
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'posts'; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = 'post_id'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'title', 'content' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = []; }
使用它来执行搜索
use App\Models\Post; Post::whereLike(['title', 'content'], 'Post title');
完成搜索后,尽情享受
报告错误
在 Twitter 上联系我 @ephraimseddor
许可证
MIT 许可证(MIT)。请参阅 许可证文件 获取更多信息。