+ /**
+ * Add the query for checking the given user id has permission
+ * within the join_permissions table.
+ * @param QueryBuilder|Builder $query
+ */
+ protected function addJointHasPermissionCheck($query, int $userIdToCheck)
+ {
+ $query->where('has_permission', '=', true)->orWhere(function ($query) use ($userIdToCheck) {
+ $query->where('has_permission_own', '=', true)
+ ->where('owned_by', '=', $userIdToCheck);
+ });
+ }
+