Download the PHP package webard/nova-eloquent-searchable without Composer
On this page you can find all versions of the php package webard/nova-eloquent-searchable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nova-eloquent-searchable
Nova Eloquent Searchable
This simple package comes with two solutions:
- Make ability to search Eloquent models by Laravel Nova way, using their search configuration
- Introduce additional search classes with optional value validating
Installation
Search Eloquent models like Nova resources
- Move
public static $search
orpublic static searchableColumns()
definition from Nova Resource to Model. -
Add trait to your Nova Resource
- Add trait to your model:
Now, you can search your models and return values the same way like in Laravel Nova panel:
To not conflict with Laravel Scout, scope was called searchInDatabase
, but if you want use other name, e.g. search
, just rename Trait method:
Now, you can search by search
method:
Additional search classes
Laravel Nova comes with some Searchable Columns Classes, but they can search only via MySQL's LIKE or full-text search.
Full-text search is powerful, but "like" searches on large datasets are very inefficient and they cannot use indexes, so this package derives several additional classes along with value validation functionality to optimize searches.
EqualValue
EqualValue
is used to search for full values. This is a simple comparison in MySQL WHERE column="value"
. This search method is useful, for example, for searching by e-mail address or telephone number.
Additionally, you can add value validation, so that if the passed value does not meet the condition, it will not be added to the search query.
EqualRelation
EqualRelation
class do the same thing as EqualValue
, but basing on relation instead of column.
Example:
FullTextValue
FullTextValue
do the same thing as SearchableText
class from Laravel Nova, but additionally adds double quote (") characters to search value. So if you search for John Doe
, to SQL query there is sent "John Doe"
value. This way, searching in full-text mode is more precise.
Of course value validation like in EqualValue
is present too.
FullTextRelation
As above, but works with relations instead of columns.
Of course value validation like in EqualValue
is present too.
TODO
I'm are actively seeking contributions to enhance this package. Here are some features I would love to see implemented:
- [ ] tests
- [ ] add
validate
method to Laravel Nova searchable classes - [ ] more searchable classes?
Contributing
We welcome contributions to improve this plugin! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with descriptive messages.
- Push your changes to your forked repository.
- Open a pull request to the main repository.
License
This project is licensed under the MIT License. See the LICENSE.md file for more details.
Contact
For questions or support, please open an issue on GitHub.