55use Illuminate \Auth \AuthenticationException ;
66use Illuminate \Foundation \Exceptions \Handler as ExceptionHandler ;
77use Symfony \Component \HttpKernel \Exception \HttpExceptionInterface ;
8+ use Illuminate \Support \Facades \Request ;
89
910class Handler extends ExceptionHandler
1011{
@@ -31,7 +32,7 @@ protected function getGuestRedirectPath(AuthenticationException $exception)
3132
3233 protected function getHttpExceptionView (HttpExceptionInterface $ e )
3334 {
34- if (current_portal () == ' admin ' ) {
35+ if ($ this -> isAdminPortal () ) {
3536 return parent ::getHttpExceptionView ($ e );
3637 }
3738
@@ -49,4 +50,40 @@ protected function getHttpExceptionView(HttpExceptionInterface $e)
4950
5051 return parent ::getHttpExceptionView ($ e );
5152 }
53+
54+ protected function isAdminPortal (): bool
55+ {
56+ $ host = Request::getHost ();
57+
58+ // get the main url
59+ $ parse = parse_url (config ('app.url ' ));
60+ $ primary_domain = str_ireplace ('www. ' , '' , $ parse ['host ' ]);
61+
62+ // get the admin domain
63+ $ admin_domain = config ('app.admin_domain ' );
64+
65+ if ($ primary_domain != $ admin_domain ) {
66+ if ($ host == $ admin_domain ) {
67+ return true ;
68+ }
69+ } elseif ($ admin_prefix = config ('app.admin_prefix ' )) {
70+ // Get the current URL
71+ $ url = Request::url ();
72+
73+ // Parse the URL
74+ $ parsed_url = parse_url ($ url );
75+
76+ // Get the path from the parsed URL
77+ $ path = $ parsed_url ['path ' ] ?? '' ;
78+
79+ // Get the first part of the path
80+ $ first_part = trim (explode ('/ ' , $ path )[1 ] ?? '' , '/ ' );
81+
82+ if ($ first_part == $ admin_prefix ) {
83+ return true ;
84+ }
85+ }
86+
87+ return false ;
88+ }
5289}
0 commit comments