Laravel 4 Fluent Query Builder - Object of class stdClass could not be converted to string

StackOverflow https://stackoverflow.com/questions/21545372

سؤال

Actually I want to use below query:

Select userid,username from users where userid not in (Select distinct fkuserid from staff);

So for that I have used:
$result=DB::table('users') -> whereNOTIN('userid',DB::table('staff') -> distinct() -> get(array('fkuserid'))) -> get(); 

but it is giving error of Object of class stdClass could not be converted to string.

هل كانت مفيدة؟

المحلول

I'm working on L3, which lacks what I've now found in L4 docs. Try:

$result=DB::table('users') -> whereNotIn('userid',DB::table('staff') -> distinct() -> lists('fkuserid')) -> get();

The lists() method should (I think) return only an array of ids as I wrote in comment.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top