diff --git a/src/Auditable.php b/src/Auditable.php index 3696afb2..3bbdad0d 100644 --- a/src/Auditable.php +++ b/src/Auditable.php @@ -71,7 +71,21 @@ trait Auditable */ public static function bootAuditable() { - if (static::isAuditingEnabled()) { + try { + $isAuditingEnabled = static::isAuditingEnabled(); + } catch (\RuntimeException $e) { + if (stripos($e->getMessage(), "facade root") === false) { + throw $e; + } + /** + * Facade root has not been set. The user may be attempting to use + * their Auditable outside of the application context. We will + * just skip booting for now. + */ + return; + } + + if ($isAuditingEnabled) { static::observe(new AuditableObserver()); } } diff --git a/tests/Unit/OutsideOfAppContextTest.php b/tests/Unit/OutsideOfAppContextTest.php new file mode 100644 index 00000000..48afec09 --- /dev/null +++ b/tests/Unit/OutsideOfAppContextTest.php @@ -0,0 +1,15 @@ +assertInstanceOf(Article::class, $article); + } +} \ No newline at end of file