Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tarikulwebx/cd638995e2c6b9f8afa5652467caf650 to your computer and use it in GitHub Desktop.
Save tarikulwebx/cd638995e2c6b9f8afa5652467caf650 to your computer and use it in GitHub Desktop.

Solution for TenancyForLaravel Tenancy Asset Not Found Problem

Suppose you uploaded an image in a Tenant workspace say test.localhost and the asset or tenant_asset helper return url like http://test.localhost:8000/tenancy/assets/2/logoipsum-381.png. When you visit the URL, it cannot detect the file and show error Tenant could not be identified on domain test.localhost.

If you facing this issue, then this solution for you.

First, make sure

  • You configured your disk properly in tenancy.filesystem and filesystem config.
  • Set tenancy.filesystem.asset_helper_tenancy false to avoid conflict with central assets.
  • If you are using spatie media library make sure, you are using TenantAwareUrlGenerator by extending DefaultUrlGenerator. Here is the ref -> laravel-medialibrary

Finally, the solution

The document says TenantAssetsController uses InitializeTenancyByDomain middleware, in my case InitializeTenancyByDomainOrSubdomain to represent my tenants.

On TenancyServiceProvider boot method add the following:

TenantAssetsController::$tenancyMiddleware = InitializeTenancyByDomainOrSubdomain::class;

If you identify your tenant by any other way, add it instead, for example: TenantAssetsController::$tenancyMiddleware = InitializeTenancyByPath::class

OR

TenantAssetsController::$tenancyMiddleware = InitializeTenancyByRequestData::class

That't it! Refresh the page now and see the magic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment