Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pavlen's avatar

Get pagination for full MySql and DB::select query

Hi,

is there a way to use Laravel pagination in this situation :

Query for full mysql search :

   $key = ' test word';

   $q = DB::select(' SELECT * , MATCH(col 1,col 2) AGAINST ("'.$key.'" IN BOOLEAN MODE) AS score FROM test WHERE MATCH(col 1,col 2) AGAINST ("'.$key.'" IN BOOLEAN MODE)');

Query is ok, I get good results, but cant use clasic ->pagination() gett error, that can use pagination on array.

Thanks, Pavle

0 likes
2 replies
gorakhyadav's avatar

$key = ' test word';

    $q = DB::selectRaw(' SELECT * , MATCH(col 1,col 2) AGAINST ("'.$key.'" IN BOOLEAN MODE) AS score FROM test 
    WHERE MATCH(col 1,col 2) AGAINST ("'.$key.'" IN BOOLEAN MODE)')->paginate(100);
pavlen's avatar

Hi in this case,get error :

Call to undefined method Illuminate\Database\MySqlConnection::selectRaw()

Please or to participate in this conversation.