@@ -49,19 +49,35 @@ public function __construct()
4949 });
5050
5151 $ 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+ );
5357 });
5458
5559 $ 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+ );
5765 });
5866
5967 $ 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+ );
6173 });
6274
6375 $ 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+ );
6581 });
6682 }
6783
@@ -639,7 +655,7 @@ public function middleware(string $middleware, callable $callback)
639655
640656 if ($ middleware === 'is ' ) {
641657 return app ()->registerMiddleware ('is ' , function ($ role ) use ($ callback ) {
642- if ($ this ->user ()?->isNot($ role )) {
658+ if (! $ this -> user () || $ this ->user ()?->isNot($ role )) {
643659 $ callback ($ role );
644660 exit ;
645661 }
@@ -648,7 +664,7 @@ public function middleware(string $middleware, callable $callback)
648664
649665 if ($ middleware === 'isNot ' ) {
650666 return app ()->registerMiddleware ('isNot ' , function ($ role ) use ($ callback ) {
651- if ($ this ->user ()?->is($ role )) {
667+ if (! $ this -> user () || $ this ->user ()?->is($ role )) {
652668 $ callback ($ role );
653669 exit ;
654670 }
@@ -657,7 +673,7 @@ public function middleware(string $middleware, callable $callback)
657673
658674 if ($ middleware === 'can ' ) {
659675 return app ()->registerMiddleware ('can ' , function ($ role ) use ($ callback ) {
660- if ($ this ->user ()?->cannot($ role )) {
676+ if (! $ this -> user () || $ this ->user ()?->cannot($ role )) {
661677 $ callback ($ role );
662678 exit ;
663679 }
@@ -666,7 +682,7 @@ public function middleware(string $middleware, callable $callback)
666682
667683 if ($ middleware === 'cannot ' ) {
668684 return app ()->registerMiddleware ('cannot ' , function ($ role ) use ($ callback ) {
669- if ($ this ->user ()?->can($ role )) {
685+ if (! $ this -> user () || $ this ->user ()?->can($ role )) {
670686 $ callback ($ role );
671687 exit ;
672688 }
0 commit comments