diff --git a/app/Abstracts/Widget.php b/app/Abstracts/Widget.php index 3ffee3164..c37566d8c 100644 --- a/app/Abstracts/Widget.php +++ b/app/Abstracts/Widget.php @@ -91,7 +91,7 @@ abstract class Widget public function view($name, $data = []) { - if (request()->isApi()) { + if (request_is_api()) { return $data; } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index dce526423..e3cf290b7 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -96,7 +96,7 @@ class Handler extends ExceptionHandler */ public function render($request, Throwable $exception) { - if ($request->isApi()) { + if (request_is_api($request)) { return $this->handleApiExceptions($request, $exception); } diff --git a/app/Traits/Companies.php b/app/Traits/Companies.php index e5cd342a2..80de9a049 100644 --- a/app/Traits/Companies.php +++ b/app/Traits/Companies.php @@ -18,7 +18,7 @@ trait Companies $request = $this->request ?: request(); - if ($this->isCompanyApiRequest($request)) { + if (request_is_api($request)) { return $this->getCompanyIdFromApi($request); } @@ -54,9 +54,4 @@ trait Companies { return (int) $request->header('X-Company'); } - - public function isCompanyApiRequest($request) - { - return $request->is(config('api.prefix') . '/*'); - } } diff --git a/app/Traits/Permissions.php b/app/Traits/Permissions.php index e091a03f6..2858d81e6 100644 --- a/app/Traits/Permissions.php +++ b/app/Traits/Permissions.php @@ -429,7 +429,7 @@ trait Permissions return; } - $table = request()->isApi() ? request()->segment(2) : ''; + $table = request_is_api() ? request()->segment(2) : ''; // Find the proper controller for common API endpoints if (in_array($table, ['contacts', 'documents'])) { diff --git a/app/Traits/Trackers.php b/app/Traits/Trackers.php index 41bb253df..689db0097 100644 --- a/app/Traits/Trackers.php +++ b/app/Traits/Trackers.php @@ -25,7 +25,7 @@ trait Trackers $app_type = 'queue'; } elseif (Str::contains($hostname, '-cron-')) { $app_type = 'cron'; - } elseif (request()->isApi()) { + } elseif (request_is_api()) { $app_type = 'api'; } elseif (app()->runningInConsole()) { $app_type = 'console'; diff --git a/app/Utilities/helpers.php b/app/Utilities/helpers.php index 73063b986..780900eb3 100644 --- a/app/Utilities/helpers.php +++ b/app/Utilities/helpers.php @@ -8,6 +8,7 @@ use App\Traits\Modules; use App\Traits\SearchString; use App\Utilities\Date; use App\Utilities\Widgets; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; if (! function_exists('user')) { @@ -313,3 +314,39 @@ if (! function_exists('is_cloud')) { return $cloud->isCloud(); } } + +if (! function_exists('request_is_api')) { + function request_is_api(Request|null $request = null): bool + { + $r = $request ?: request(); + + return $r->is(config('api.prefix') . '/*'); + } +} + +if (! function_exists('request_is_auth')) { + function request_is_auth(Request|null $request = null): bool + { + $r = $request ?: request(); + + return $r->is('auth/*'); + } +} + +if (! function_exists('request_is_signed')) { + function request_is_signed(Request|null $request = null, int $company_id): bool + { + $r = $request ?: request(); + + return $r->is($company_id . '/signed/*'); + } +} + +if (! function_exists('request_is_portal')) { + function request_is_portal(Request|null $request = null, int $company_id): bool + { + $r = $request ?: request(); + + return $r->is($company_id . '/portal') || $r->is($company_id . '/portal/*'); + } +}