0

I am getting Getting Call to a member function paginate() on array error in laravel with the following code

public static function search_query($query)
{
    $tokenizeitem = array();
    $tokenizeitem = queryarr($query);

    //$tokenizeitem = $this->bbbootstrap->tokenizeStringIntoFTSWords($item);

    $sql = "SELECT * FROM snippets WHERE MATCH(snippets_name,seo_description) 
    AGAINST (' ";

    foreach ($tokenizeitem as $w) {
        $sql .= '+' . $w . '* ';
    }

    $sql .= "' IN BOOLEAN MODE)";

    $searchdata=DB::select( DB::raw($sql))->paginate(15);

    return $searchdata;
}
Douwe de Haan
  • 6,247
  • 1
  • 30
  • 45
Upasana Chauhan
  • 948
  • 1
  • 11
  • 32

1 Answers1

0

The error is self explanatory:

Call to a member function paginate() on array error in laravel

your following code:

DB::select( DB::raw($sql))->paginate(15);

return an array and you can't call paginate() on array. So instead of this use:

DB::table("your query")->paginate();

Laravel Raw Query Reference

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59