rrkhatri/laravel-keywordable

Add keywords on model and filter models using keywords.

dev-master / 1.x-dev 2022-11-14 14:59 UTC

This package is auto-updated.

Last update: 2024-04-14 18:26:59 UTC


README

This package is used to bind searchable keywords on model. Which you can directly use in your query.

Setup:

Publish model & trait by executing below command.

php artisan vendor:publish --provider="RrKhatri\Keywordable\KeywordServiceProvider"

Migrate keywords table

php artisan migrate

Usage:

  • Keywordable trait should be added on model.
  • Sync keywords on model.
$model->syncKeywords("laravel", "coder"); // ["laravel", "coder"] -> both will work.
  • Search models having matching keywords.
$query->havingKeywords("lara", "co"); // orHavingKeywords -> to apply filter as OR.
  • Find models having exact keywords.
$query->havingExactKeywords("laravel", "coder"); // orHavingExactKeywords -> to apply filter as OR.
  • Remove keywords from model.
$model->removeKeywords(); // will remove all keywords.
$model->removeKeywords("laravel"); // will remove specified keyword(s).

Licence

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Buy us a tree