I'm working on a Laravel installation where I have (among other things)
- Teachers (table:users (cols: id, name, type), model:User, users.type = 2)
- Students (table:users (id, name, type), model:User, users.type = 1)
- Schools (table:schools (id, name), model:School)
- Collections of students (table:student_collection (id, name), model:StudentCollection)
- & table students_collections (id, user_id, collection_id)
I have managed to setup some relationships, but can't get my head around to get
- Which teachers teach a student
- Which collections does a student belong to
Currently I'm trying to get the collections with
//User.php
public function collections() {
return $this->belongsToMany('\App\StudentCollection', 'student_collections_users', 'collection_id', 'user_id');
}
but it returns an empty result.
I'm using Laravel 5.3.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire