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

1.3k views Asked by At

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;
}
1

There are 1 answers

6
Mayank Pandeyz On

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