mardi 21 mai 2019

Laravel 5.4 - multiple relations in few tables

In a picture below we can see relations between my tables. My target is to get "type" from driver_license_types. Starting at user object. For example:

$user = User::find(1);

and from there I need to get type from driver_license_types. Important thing is that instructors can have few records in instructor_license_types table, like this: Records instructor_license_types Relations between my tables

My current solutions:

  • In User model I create method instructor which is relation "belongTo" instructor model.
  • in Instructor model I created method license which is relation "hasMany" with Instructor_license_types
  • In Instructor_license_types, I create method types which is relation "hasMany" with Driver_license_types.

And final code look like: enter image description here

Is there any better solutions?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire