Search code examples
laravellaravel-5eloquentslim-3

Can not use '$query' in slim 3 with Laravel eloquent


I use slim 3 for microservice for that i install laravel eloquent and i write a laravel query like following

use Illuminate\Database\Capsule\Manager as DB;

DB::enableQueryLog();

$faqs = DB::table('rental_faq')
    ->where('id', '!=', '')
    ->where(function ($query) {
        $query->where('isActive', '=', 1)
            ->orWhere('isDelete', '=', 'no');
    })
    ->get();

then the problem is it shows a error like following

" There was an error parsing JSON data Unexpected token I in JSON at position 743 "

I want to perform and_where and or_where operation separated parenthesis


Solution

  •  $maincat=25;
     $subcat=30;
    
    $faqs=DB::table('rental_faq')
             ->where('isActive',1)
             ->where('isDelete','no')
             ->where(function ($query) use($maincat,$subcat) {
                    $query->where('main_category',$maincat)
                          ->whereRaw('FIND_IN_SET(?,sub_category)',[$subcat]);
    
            })
     ->get();