Hello again :)
I have problem!
One user has access to multiple clusters for example schools. Each school has different Classes and Lessons, assigned for this user.
So my problem is -
How to get to correct Classes and Lessons
I was using
class Course extends Model
public $hasMany = [
'lessons' => [
'LoginGrupa\Mbook\Models\Service',
'scope' => 'authLessons',
'order' => 'order asc',
],
In my scope I check to witch to witch cluster/school user belongs, and display correct data.
public function scopeAuthLessons($query)
{
if (\BackendAuth::getUser()) {
return $query->where('school_id', '=', \BackendAuth::getUser()->current_cluster_id);
}
if (\Auth::getUser()) {
return $query->where('school_id', '=', \Auth::getUser()->current_cluster_id);
}
return $query;
// TODO: Add this check only for Add services view
// ->whereNull('course_id')
}
But I do not like this approach, because, I need to all the time check when the user changes cluster, and store it in DB How would you solve this problem?
Last updated