nickdavies07
1 year ago

Accesing data from base tables and pivot tables

Posted 1 year ago by nickdavies07

Cannot get my head round this one.

I have the following:

  • schools (id, name)

  • categories (id, name)

  • types (id, name)

  • Schools can have many Categories and vice versa (pivot as category_school) - (id, category_id, school_id)

  • Types can have many Categories and vice versa (pivot as category_type) - (id, category_id, type_id)

I'm trying to get the data from all tables so I can populate a dropdown select box based on the chosen School and Type. So if a user selects School A, then Type C, all the categories should list for School A and Type C.

Can't figure out how I would access the all the data to be able to do this. So far all I've been able to do is something like $categories = Type::find(request('type'))->categories; to get the categories based on the type requested.

Screen grab of select boxes. https://pasteboard.co/HDHjtey.png

Please sign in or create an account to participate in this conversation.