First Method
$subQuery = \DB::table('users')
->select('company_id')
->where(['user_type' => 'advisor'])
->groupBy('company_id');
DB::table('companies')
->whereRaw('companies.id In ('.$subQuery->toSql().')')
->addBinding($subQuery->getBindings())
->update(['is_client' => true]);
Second Method
DB::table('companies')
->whereIn('companies.id',function($query){
$query->select('company_id')
->from('users')
->where(['user_type' => 'advisor']) -
>groupBy('company_id'); })
->update(['is_client' => true]);
Comments
Post a Comment