Merge branch 'issue-184' into 'le-gaulois-2024'
fix: ✨ product search are now case insensitive
See merge request ldc-web/projets/le-gaulois!150
This commit is contained in:
commit
03c822e931
1 changed files with 5 additions and 4 deletions
|
|
@ -315,20 +315,21 @@ class Controller extends BaseController
|
|||
string|null $search = null
|
||||
): \Illuminate\Pagination\LengthAwarePaginator {
|
||||
$modelsTitles = [];
|
||||
$query->when(!is_null($search), function (Builder $q) use ($search, $searchField) {
|
||||
$q->where($searchField, 'like', "%{$search}%");
|
||||
$searchLower = Str::lower($search);
|
||||
$query->when(!is_null($search), function (Builder $q) use ($searchLower, $searchField) {
|
||||
$q->where($searchField, 'like', "%{$searchLower}%");
|
||||
})
|
||||
->where('published', true)
|
||||
->inRandomOrder()
|
||||
->pluck($searchField)
|
||||
->each(function (string $title) use (&$modelsTitles, $search) {
|
||||
->each(function (string $title) use (&$modelsTitles, $searchLower) {
|
||||
if (count($modelsTitles) < 5) {
|
||||
foreach (explode(" ", $title) as $word) {
|
||||
$word = Str::lower($word);
|
||||
if (
|
||||
strlen($word) > 3
|
||||
&& !in_array($word, $modelsTitles)
|
||||
&& ((!is_null($search)) ? str_contains($word, $search) : true)
|
||||
&& ((!is_null($searchLower)) ? str_contains($word, $searchLower) : true)
|
||||
) {
|
||||
$modelsTitles[] = $word;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue