alirezaghasemi / laravel-searchable
为模型添加搜索功能的 Laravel 包。
1.0.0
2023-03-27 09:59 UTC
Requires
- php: ^8.0
- illuminate/database: *
- illuminate/support: *
README
为模型添加搜索功能的 Laravel 包
安装
composer require alirezaghasemi/laravel-searchable
用法
- 在您的模型中使用
Searchable
特性 - 在您的模型中定义
$searchable
属性以选择要搜索的列
示例(用户模型与帖子关联)
use AlirezaGhasemi\LaravelSearch\Searchable;
class User extends Model {
use Searchable ;
protected $searchable = ['name', 'mobile', 'posts.title','posts.comments.title'];
public function posts(){
return $this->hasMany(Post::class);
}
示例(帖子模型与评论关联)
class Post extends Model {
public function comments(){
return $this->hasMany(Comment::class);
}