I should of also mentioned im new here and a beginner, i have searched extensively through forums/stackoverflow and github projects but My question is more basic and all other scenarios i've found confuse me more
How does Eloquent know which client I need?
I'm planning how i will implement the below using Eloquent & Laravel version 8:
Users have many clients, Clients only have one user.
Each client has many appointments, each appointment only has one client.
Say I'm User 1 and i click on client 17 and query to show their appointments. How do i set it up so that it only shows user 1 > client 17 > appointments and not pull user 2 > client 17 > appointments ?
its very hard for me to word this simply as i don't fully understand it myself so apologies in advance if this makes no sense. essentially I have users who each have clients and those clients have appointments but each users data needs to be separate to every other user.
It sounds that you are looking for ensuring that every user sees his own clients and the data belonged to it.
This is quite easy using policies:
https://laravel.com/docs/8.x/authorization#creating-policies
Relations you need:
- User has many clients: one to many (clients table should has user_id)
- Client has many appointments: one to many (appointments table has client_id)
Please or to participate in this conversation.