File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,21 @@ trait Auditable
7171 */
7272 public static function bootAuditable ()
7373 {
74- if (static ::isAuditingEnabled ()) {
74+ try {
75+ $ isAuditingEnabled = static ::isAuditingEnabled ();
76+ } catch (\RuntimeException $ e ) {
77+ if (stripos ($ e ->getMessage (), "facade root " ) === false ) {
78+ throw $ e ;
79+ }
80+ /**
81+ * Facade root has not been set. The user may be attempting to use
82+ * their Auditable outside of the application context. We will
83+ * just skip booting for now.
84+ */
85+ return ;
86+ }
87+
88+ if ($ isAuditingEnabled ) {
7589 static ::observe (new AuditableObserver ());
7690 }
7791 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace OwenIt \Auditing \Tests \Unit ;
4+
5+ use OwenIt \Auditing \Tests \Models \Article ;
6+ use PHPUnit \Framework \TestCase ;
7+
8+ class OutsideOfAppContextTest extends TestCase
9+ {
10+ public function test_can_create_new_model (): void
11+ {
12+ $ article = new Article ();
13+ $ this ->assertInstanceOf (Article::class, $ article );
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments