Your where clauses are not the same:
Setter.id = status.setter_id
and
->where('setter.id','=','status.user_id')
I made it but it still does not work :(
DB::table(DB::raw('users as user,users as setter,status'))
->where('user.id','=','status.user_id')
->where('setter.id','=','status.setter_id')
->where('status.user_id','=',$id)
->select('user.full_name as user_full_name','setter.full_name as setter_full_name','status.content','status.created_at')
->get();
I would design this as join rather than putting multiple tables in a DB::raw
What sql is it generating (replace your "->get()" with "->toSql()" and echo it out)
result
select `user`.`full_name` as `user_full_name`, `setter`.`full_name` as `setter_full_name`, `status`.`content`, `status`.`created_at` from users as user,users as setter,status where `user`.`id` = ? and `setter`.`id` = ? and `status`.`user_id` = ?
work true :)
DB::table('status')
->join('users as user','user.id','=','status.user_id')
->join('users as setter','setter.id','=','status.setter_id')
->where('status.user_id','=',$id)
->select('user.full_name as user_full_name','setter.full_name as setter_full_name','status.content','status.created_at')
->get();
Yes, the problem is it, thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community