mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:14:04 +00:00
Finish path identification - configurability & exception handling
This commit is contained in:
parent
cb2bd018aa
commit
494d274798
4 changed files with 83 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ namespace Stancl\Tenancy\Middleware;
|
|||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Stancl\Tenancy\Exceptions\RouteIsMissingTenantParameterException;
|
||||
use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
|
||||
|
|
@ -27,15 +28,16 @@ class InitializeTenancyByPath extends IdentificationMiddleware
|
|||
/** @var Route $route */
|
||||
$route = $request->route();
|
||||
|
||||
// todo test the behavior described by the comment
|
||||
// Only initialize tenancy if tenant is the first parameter
|
||||
// We don't want to initialize tenancy if the tenant is
|
||||
// simply injected into some route controller action.
|
||||
if ($route->parameterNames()[0] === 'tenant') {
|
||||
if ($route->parameterNames()[0] === PathTenantResolver::$tenantParameterName) {
|
||||
return $this->initializeTenancy(
|
||||
$request, $next, $route
|
||||
);
|
||||
} // todo else case should probably throw exception about malformed route? or do we just leave that as the developer's responsibility?
|
||||
} else {
|
||||
throw new RouteIsMissingTenantParameterException;
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue