@@ -49,19 +49,35 @@ public function __construct()
49
49
});
50
50
51
51
$ this ->middleware ('is ' , function ($ role ) {
52
- \Leaf \Exception \General::default404 ();
52
+ \Leaf \Exception \General::error (
53
+ '404 ' ,
54
+ '<p>The page you are looking for could not be found.</p> ' ,
55
+ 403
56
+ );
53
57
});
54
58
55
59
$ this ->middleware ('isNot ' , function () {
56
- \Leaf \Exception \General::default404 ();
60
+ \Leaf \Exception \General::error (
61
+ '404 ' ,
62
+ '<p>The page you are looking for could not be found.</p> ' ,
63
+ 403
64
+ );
57
65
});
58
66
59
67
$ this ->middleware ('can ' , function () {
60
- \Leaf \Exception \General::default404 ();
68
+ \Leaf \Exception \General::error (
69
+ '404 ' ,
70
+ '<p>The page you are looking for could not be found.</p> ' ,
71
+ 403
72
+ );
61
73
});
62
74
63
75
$ this ->middleware ('cannot ' , function () {
64
- \Leaf \Exception \General::default404 ();
76
+ \Leaf \Exception \General::error (
77
+ '404 ' ,
78
+ '<p>The page you are looking for could not be found.</p> ' ,
79
+ 403
80
+ );
65
81
});
66
82
}
67
83
@@ -639,7 +655,7 @@ public function middleware(string $middleware, callable $callback)
639
655
640
656
if ($ middleware === 'is ' ) {
641
657
return app ()->registerMiddleware ('is ' , function ($ role ) use ($ callback ) {
642
- if ($ this ->user ()?->isNot($ role )) {
658
+ if (! $ this -> user () || $ this ->user ()?->isNot($ role )) {
643
659
$ callback ($ role );
644
660
exit ;
645
661
}
@@ -648,7 +664,7 @@ public function middleware(string $middleware, callable $callback)
648
664
649
665
if ($ middleware === 'isNot ' ) {
650
666
return app ()->registerMiddleware ('isNot ' , function ($ role ) use ($ callback ) {
651
- if ($ this ->user ()?->is($ role )) {
667
+ if (! $ this -> user () || $ this ->user ()?->is($ role )) {
652
668
$ callback ($ role );
653
669
exit ;
654
670
}
@@ -657,7 +673,7 @@ public function middleware(string $middleware, callable $callback)
657
673
658
674
if ($ middleware === 'can ' ) {
659
675
return app ()->registerMiddleware ('can ' , function ($ role ) use ($ callback ) {
660
- if ($ this ->user ()?->cannot($ role )) {
676
+ if (! $ this -> user () || $ this ->user ()?->cannot($ role )) {
661
677
$ callback ($ role );
662
678
exit ;
663
679
}
@@ -666,7 +682,7 @@ public function middleware(string $middleware, callable $callback)
666
682
667
683
if ($ middleware === 'cannot ' ) {
668
684
return app ()->registerMiddleware ('cannot ' , function ($ role ) use ($ callback ) {
669
- if ($ this ->user ()?->can($ role )) {
685
+ if (! $ this -> user () || $ this ->user ()?->can($ role )) {
670
686
$ callback ($ role );
671
687
exit ;
672
688
}
0 commit comments