Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top