I currently working on a laravel 5.4 project where I'm trying to find values in my database that are similar to a search string introduced. For example, I have the following search term
$search_term = "Some long phrase with words"
and in my database (MySQL) I have a table tags with a column value. One row in this table would have value => 'some', another row might have value => 'long', and another row might have value => 'phra'
What I need is to create a collection of all tags where the value appears in my search term. Which means the 3 rows i mentioned should match for my $search_term
I currently know that I can use eloquent in laravel and say something like
Tag::where('value', 'like', "%".$search_term."%")->get()
But as far as I understand this would see if the $search_term is a sub-string of what's in the value column.
How can I use eloquent to ask if value is contained (a sub-string) in $search_term?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire