Gaurav Singh
Gaurav Singh

Reputation: 5

I want to use pagination with laravel Raw query builder

Here is my Raw query

$searchData=DB::select('SELECT * FROM hostretreats WHERE (furnishing_type= "'.$typesearchkeyword.'" OR prop_type="'.$typesearchkeyword.'") AND approved = 1');

Help me how can I fix it?

Upvotes: 0

Views: 62

Answers (1)

IndianCoding
IndianCoding

Reputation: 2683

You should rewrite select query with DB methods.

$searchData = DB::table('hostretreats')
    ->where(function($query) use ($typesearchkeyword){
        $query
            ->where('furnishing_type', $typesearchkeyword)
            ->orWhere('prop_type', $typesearchkeyword);
    })
    ->where('approved', 1)
    ->paginate(10);

Upvotes: 1

Related Questions