Since its an authorization part, you can use Gate at Laravel [1].
Another approach can be establishing relationships between user and job site. Then you just check whether that user is eligible for modify or not by using logic.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, i am plugging away at my app and i am required to have team owners to be able to edit / update / delete all of the the team members job sites but i am not sure how to build the proper query. I currently have this query to retrieve the sites for the current user
$jobSites = DB::table('job_sites')->where('user_id', auth()->id())->get();
but i am not sure how to modify it so i can get the job sites for all of the users on a given team if the current user is the owner of the team. I tried looking through the docs but only see conditional logic for team stuff and nothing seemed obvious to me.
Any suggestions would be extremely helpful!! thanks in advance :)
This should do it, or be pretty close... could be shorter but wanted it to be verbose for self-explanation
if (auth()->user()->roleOnCurrentTeam() == 'owner') {
$teamMembers = auth()->user()->currentTeam->users;
$memberIds = $teamMembers->pluck('id');
$jobSites = DB::table('job_sites')->whereIn('user_id', $memberIds)->get();
}
Please or to participate in this conversation.