public static function allExceptoCurso($curso_id) { $GLOBALS['id'] = $curso_id; $documentaciones = Curso::find($curso_id)->documentacion()->select('documentacion_id')->get(); $docs = array(); foreach ($documentaciones as $documentacion) { $docs[] = $documentacion->documentacion_id; } $GLOBALS['docs'] = $docs; $documentacion = Documentacion::join('documentacion_cursos', function ($join) { $join->on('documentacion_cursos.documentacion_id', '=', 'documentacion.id'); })->where('documentacion_cursos.curso_id', '!=', $GLOBALS['id']); if (!empty($GLOBALS['docs'])) { $documentacion->whereNotIn('documentacion.id', $GLOBALS['docs']); } return $documentacion->get(); }