role === 'super_admin') { return; } // Candidates don't have a tenant_id but must access // quizzes/job positions linked to their position if ($user->role === 'candidate') { return; } if ($user->tenant_id) { $builder->where(function ($query) use ($user) { $query->where('tenant_id', $user->tenant_id) ->orWhereNull('tenant_id'); }); } } }); static::creating(function ($model) { if (Auth::check() && Auth::user()->tenant_id && Auth::user()->role !== 'super_admin') { $model->tenant_id = Auth::user()->tenant_id; } }); } public function tenant() { return $this->belongsTo(\App\Models\Tenant::class); } }