Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Your where clauses are not the same:

Setter.id = status.setter_id

and

 ->where('setter.id','=','status.user_id')
Last updated 1 year ago.
0

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();
Last updated 1 year ago.
0

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)

Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ahmadina ahmadina Joined 6 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.