I am encountering an issue when it comes to displaying users based on locations.
The problem lies in the fact that it only shows the user and not the users associated with the locations.
What I desire is for the user to see only the users located in the places linked in the 'location_user' table.
I acknowledge that the issue stems from 'location_user', 'location_user.user_id', '=', 'users.id'
However, I prefer a solution that is more intelligent and does not involve adding a column named location_id to the user list
This is because I require support for multiple locations
This pertains to the data in UsersController.php
$data = User::leftjoin('location_user', 'location_user.user_id', '=', 'users.id')
->where('location_user.user_id', auth()->user()->id)
->leftjoin('locations', 'locations.id', '=', 'location_user.location_id')
->where('locations.status', '1')
->select('users.*',)
->orderBy('status', 'DESC')->get();
Tables
users: https://i.sstatic.net/h3dID.jpg
location_user: https://i.sstatic.net/6KGZN.jpg
locations: https://i.sstatic.net/UDbDJ.jpg
Can someone assist me with this challenge?
Thank you.