Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. A School hasMany Batches.
  2. A Batch belongsTo a School.
  3.  
  4. A Batch hasMany Students.
  5. A Student belongsTo a Batch.
  6.  
  7. A User hasMany Schools.
  8. A School belongsTo a User.
  9.  
  10. (A User in this system is a person external to the school that goes in
  11. and provides teaching services to the students on a weekly basis).
  12.  
  13. $student->batch->school->user;
  14.  
  15. A Student BelongsTo a School.
  16. A School hasMany Students.
  17.  
  18. $student->school->user;
  19.  
  20. public function view(User $user, Student $student) {
  21.  
  22. // only the user that a student 'belongsTo' can view them
  23.  
  24. return $user->id === $student->batch->school->user->id;
  25.  
  26. // OR
  27.  
  28. return $user->id === $student->school->user->id;
  29.  
  30. }
  31.  
  32. // Student Model (simplified, obviously)
  33.  
  34. $this->belongsTo(School::class);
  35.  
  36. $this->belongsTo(Batch::class);
  37.  
  38. $this->belongsTo(User::class);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement