Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Query Builder Search (match against)

Tags:

php

mysql

laravel

I'm trying to write this query in Laravel

select *, MATCH(hobbies)AGAINST('soccer') from users where MATCH(hobbies)AGAINST('soccer' IN BOOLEAN MODE) LIMIT 10 OFFSET 0;

I have looked in the documentation on query builder but didn't find anything on full-text search.

Please help.

Thank you in advance :)

like image 691
Marc Avatar asked Dec 05 '22 17:12

Marc


2 Answers

User::selectRaw("*, MATCH(hobbies)AGAINST('soccer')")
    ->whereRaw("MATCH(hobbies)AGAINST('soccer' IN BOOLEAN MODE)")
    ->limit(10);
like image 200
Tang3 Avatar answered Dec 09 '22 15:12

Tang3


Thanks to Samsquanch he pointed me in the right direction. Here is how I got it done.

$my_query = "select *, MATCH (name) AGAINST (?) from users 
    where MATCH (hobbies) AGAINST (? IN BOOLEAN MODE) limit 10 OFFSET ?"

$hobbies = DB::select($my_query, array($search_term, $search_term, (($page-1)*10)));
like image 29
Marc Avatar answered Dec 09 '22 16:12

Marc