When i join two tables in search handler there is a same column in both tables, i cannot access the value of left table
for example if there are two tables user and volunteers they both have id column when I write a search handler like this
$builder->join('users', 'volunteers.user_id', "=", "users.id")
->join('policies','volunteers.policy_id',"=","policies.id")
->where(function($q) use ($whereConditions){
$q->where('users.first_name','like','%'.$whereConditions['OR'][0]['value'].'%');
$q->orWhere('users.last_name','like','%'.$whereConditions['OR'][0]['value'].'%');
$q->orWhere('policies.name','like','%'.$whereConditions['OR'][0]['value'].'%');
$q->orWhere('volunteers.experiences','like','%'.$whereConditions['OR'][0]['value'].'%');
$q->orWhere('volunteers.medical_facility','like','%'.$whereConditions['OR'][0]['value'].'%');
});
and when i query, it will return user id as volunteer id
I want the volunteer id but I always get the user id. I hope the question is clear
2
Answers
To fix this issue, you need to make sure that you are using the correct column names in your join statement. If the volunteers table has a column named volunteer_id which represents the ID of a volunteer, you should update your code like this:
In the above code, I assumed that the column volunteer_id exists in the volunteers table and represents the ID of a volunteer. Make sure to replace volunteer_id with the correct column name if it differs in your database schema.
By updating the join condition to use the correct column name, you should be able to retrieve the volunteer ID instead of the user ID in your query results.
I implemented your problem and the problem happened to me but I solved it by using
$builder->select('your columns')
.