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