Ankit Sompura Ankit Sompura - 6 months ago 61
PHP Question

Laravel whereIn with a where clause ErrorException in Grammar.php line 118:

Below is my laravel query:

$statusCondition = '[1]';

$users = DB::table('user_tracking')
->join('user_detail', 'user_tracking.user_id', '=', 'user_detail.id')
->select('user_tracking.*', 'user_detail.gender', 'user_detail.username', 'user_detail.auth_provider')
->where('user_tracking.art_id','=','1')
->where('user_tracking.visit_start_date','>',DB::raw('NOW()-INTERVAL 24 HOUR'))
->whereIn('user_tracking.status',$statusCondition)
->get();


When I'm using whereIn then given below error can anyone help to resolved such issue:

ErrorException in Grammar.php line 118: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in /var/sites/l/letsnurture.co.uk/public_html/demo/museum/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 315 and defined

Answer

$statusCondition should be an array.

Replace

$statusCondition = '[1]';

with

$statusCondition = [1];
Comments