osamaalmamri/laravel-search

这是我创建的包 laravel-search

1.0 2023-09-07 08:55 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

此包简化了具有复杂关系的模型搜索

安装

您可以通过 composer 安装此包

composer require osamaalmamri/laravel-search

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="laravel-search-config"

这是发布配置文件的内容

return [

// this is the key namein Request $request 
 'key' => "search"
];

使用方法

在模型中使用 searchable 类

use OsamaAlmamri\LaravelSearch\Searchable;

class YourModal extends Model
{
  use Searchable;
  
  // define the name of cols 
  //if you need search in another fields of another table using the relation name then col name
  // you can search any  related relation as the following
      public $searchable = ['name','description','user.name','user.phone','user.role.name'];
}

致谢

许可协议

MIT 许可协议 (MIT)。请参阅 许可文件 了解更多信息。