🔍 Generates database queries based on one unique string
MIT License
Full Changelog: https://github.com/lorisleiva/laravel-search-string/compare/v1.2.0...v1.3.0
Published by lorisleiva over 2 years ago
Full Changelog: https://github.com/lorisleiva/laravel-search-string/compare/v1.1.3...v1.2.0
Published by lorisleiva over 3 years ago
Make order by and select keyword rules use column aliases (See #34)
Published by lorisleiva over 3 years ago
Add case_insensitive
option for search queries — defaults to false
for backward compatibility. (See #22)
You can set it to true
in your options amongst columns
and keywords
. For example, in the config/search-string.php
file:
return [
'default' => [
'case_insensitive' => true, // <- Globally.
// ...
],
Article::class => [
'case_insensitive' => true, // <- Only for the Article class.
// ...
],
];
When set to true
, it will lowercase both the column and the value before comparing them using the like
operator.
$value = mb_strtolower($value, 'UTF8');
$query->whereRaw("LOWER($column) LIKE ?", ["%$value%"]);
Published by lorisleiva over 3 years ago
Published by lorisleiva over 3 years ago
Use qualify column names to avoid ambiguous conflicts (See #32)
Published by lorisleiva about 4 years ago
🚑 Fix searchable columns inside relationships (#27)
Published by lorisleiva about 4 years ago
⬆️ Add support for Laravel 8
Published by lorisleiva about 4 years ago
Fix resolve conflict with HOA protocol
Published by lorisleiva over 4 years ago
🚑 Allow CompilerInterface to handle null input instead of throwing a TypeError (#20).
Published by lorisleiva over 4 years ago
You can now query a model's relationships. For example:
comments > 3
comments
(equivalent to comments > 0
)category.name: Laravel
category: (name: Laravel or name: Vuejs)
comments: (author: (name: johndoe))
comments.author.name: johndoe
Three artisan commands have been added allowing you to play with the search string syntax.
php artisan search-string:ast <model> <query>
: Dumps the tree (AST) generated by the query.php artisan search-string:sql <model> <query>
: Dumps the SQL generated by the query.php artisan search-string:get <model> <query>
: Returns the results generated by the query.For example: php artisan search-string:sql User "name = John"
The entire parser has been re-written using an Llk compiler compiler (from HOA).
This allows us to define the entire syntax as a grammar that itself gets compiled into a compiler (you can see the grammar here if that's your type of thing). As a result, the generated parser is a lot more robust and more test have been written to make sure of that. Additionally, it makes the parser easier to maintain and to add new features.
operator
and value
for the column options. Matching operators was a pointless task since they were hardcoded in the search string syntax and matching the value became redundant when adding the map
column option (which I am planning on making more flexible in the future).Published by lorisleiva over 4 years ago
✨ Add value mapping. You can now add a map
to your column options that will transform any value entered by the user into something that your database understands.
// With these column options...
protected $searchStringColumns = [
'support_level_id' => [
'key' => 'support_level',
'map' => [
'testing' => 0,
'community' => 1,
'official' => 2,
]
],
];
// "support_level:testing" will generate:
$query->where('support_level_id', '=', 0);
// "support_level:another_value" will generate:
$query->where('support_level_id', '=', 'another_value');
As you can see from that last example, if a user enters a value which is missing from the map
option, it will simply be passed as-is. This makes it possible to use the map
option as a way to define value aliases.
If you'd like to ensure that any value missing from that mapping generates an InvalidSearchStringException
, then you should adjust the value
option accordingly. Here is what that would like for our example above.
protected $searchStringColumns = [
'support_level_id' => [
'key' => 'support_level',
'value' => '^testing|community|official$' // <= Whitelist your option using a regex
'map' => [
'testing' => 0,
'community' => 1,
'official' => 2,
]
],
];
Published by lorisleiva over 4 years ago
⬆️ Add support for Laravel 7
Published by lorisleiva about 5 years ago
⬆️ Add support for Laravel 6
Published by lorisleiva over 5 years ago
🚑 Fixes column aliases (#3)
Published by lorisleiva over 5 years ago
🚑 Support versions greater than 5.8.0 (#2)
Published by lorisleiva over 5 years ago
⬆️ Support Laravel 5.7 and 5.8
Published by lorisleiva over 6 years ago