mardi 28 février 2017

Return search results matching multiple query tags?

I'm using OctoberCMS based on Laravel.

I have an html search field which query string is parsed with php.

Laravel returns database results based on the url tag parameter using MySQL WHERE LIKE.

It works with 1 tag, but how to return results matching multiple tags separated by commas or spaces?

HTML5 Search Input

<form action="/search">
  <input type="search" name="tags" multiple>
  <button type="submit">search</button>
</form>

Single tag search

localhost/search?tags=galaxy

Multiple tag search

commas localhost/search?tags=galaxy%2C+stars%2C+universe
spaces localhost/search?tags=galaxy+stars+universe

This should return any tags matching in the database table's tags column.

The problem is that it sees the query as galaxy AND stars AND universe and not individual tags: galaxy, stars, universe.

Search Results

$query_string = $tags = '';

$query_string = getenv('QUERY_STRING');

// Return search results matching query string
return $query->where('tags', 'like', "%$tags%");

$query is part of OctoberCMS.

Example

results

Problem

problem



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2m4xakS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire