mardi 29 janvier 2019

Laravel/Eloquent get all appointments from a polymorphic "member_id" through a appointment_members table

I have an appointments table and an appointment_members table and my users need to be able to get a collection of appointments by searching with a "member_id", which could be a Person, Incident or CustomerID. The appointment_members table has member_id and appointment_id columns, so the member_type (also a column) is irrelevant. This all set up by a previous dev and what is missing are the relationships on the Eloquent models. I'm just creating a simple GET route that needs to return any/all appointments by that member_id. Each row has one appointment, so if I were to pass in a member_id that returned 10 results, some could have appts and others not, but at the end of the day I just need a collection of appts that are related to that member_id. Here's a screenshot of the appointment_members table: enter image description here

If I create a simple hasOne relationship to appointments on appointment_members:

public function appointments()
{
    return $this->HasOne(Appointment::class, 'id', 'appointment_id');
}

I can get a collection of appointment_members with it's respective appointment, but not sure how I boil it down to just getting the appointments.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2DGElYR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire