0

I have temporary problem with my project. I am creating a School Management System in Laravel. I have also implemented “spatie/laravel-permission”.

I have some roles: Student, Teacher, Parent, Headmaster etc.

I have some permissions: Add Grade / Edit Grade / Add Absence etc.

Everything works, yep. But the problem is that every student should be assigned to a class (I mean a class in school). How can I edit “spatie/laravel-permission” to implement what I want: if authenticated user is a student he should have also a class, and then type something like:

$thirdClass = User::role('student')->withClass('thirdClass')->get();

to get all users of this class?

I hope you understand what I mean, because my english is not so good as I think propably. I will appreciate every advice how to do it. Have a nice day!

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Tomek Greber
  • 5
  • 1
  • 7
  • 1
    if i understand you correctly, your class-binding to students is not depended on roles and permissions. you have (or should make) Student model, and maybe Class model, or just class field in Student model. So, in that case, you need just get class of student and then get other students with the same class – Roman Meyer Mar 08 '19 at 12:20

1 Answers1

0

You can use a where method, but only in case where information about class is in the same table (of course You always can use a class_id as a first parameter if you have relation):

User::role('student')->where('class', 'thirdClass')->get();

If you have relation and also want to get information about class, simply use with method:

User::role('student')->where('class_id', $classId)->with('class')->get();
Harven
  • 608
  • 6
  • 15