Update Livewire integration for Tenancy by path
I made some minor changes to @FelipeVeiga proposal and added them to the documentation.
See https://github.com/archtechx/tenancy/issues/628#issuecomment-1161863700
@lukinovec can you test this, check why the build is failing, and see if file uploads work for you: https://github.com/archtechx/tenancy/issues/628#issuecomment-1294871486
see if file uploads work for you
I couldn't make them work yet. When I select a file, LW sends a post request to livewire/upload-file (no tenant ID in the path). I get a response saying InitializeTenancyByPath failed because the route doesn't have any parameters (the check for $route->parameterNames()[0] === PathTenantResolver::tenantParameterName() in the middleware fails). I tried using UniversalRoutes, also didn't work. I noticed that UniversalRoutes has the $identificationMiddlewares array and that InitializeTenancyByPath wasn't there, so I added it, but still, I'm getting the same error.
I don't think universal routes would fix anything here. They're a thing that's for domains, and even if they worked here, it would just skip tenant identification which is not what we want.
Instead, the approach should be customizing the path used for file uploads, similar to the other change that was made here.
I see. For me, LW works with the prefixed message path after following the integration guide, but the upload-file path remains the same.
Try to focus on finding if this is possible:
Instead, the approach should be customizing the path used for file uploads, similar to the other change that was made here.
Adding
Route::post('/livewire/upload-file', [FileUploadHandler::class, 'handle'])->name('livewire.upload-file');
to the tenant routes fixed the file uploads (same place where the guide suggests adding the livewire/message/{name} route). It overrides the livewire.upload-file route used by LW. But that breaks the central app. Having InitializeTenancyByPath::class in the middleware_group array in the LW config also breaks the central app.
Also, we should put window.livewire_app_url = '/{{ tenant()->id }}'; inside a check (@if(tenant())) to not break the central app.
@lukinovec So is it possible to make LW work in both tenant & central apps with path identification? I think in our convo on BC it seemed that it's not, but here you're suggesting adding an @if() check that might fix that.
here you're suggesting adding an
@if()check that might fix that.
That only fixes a smaller problem this PR has (it assumes that tenant() is not null, and that makes visiting pages on the central domain throw an exception), but it doesn't help with the main problem described in the first paragraph of my previous comment. So making LW work in both tenant & central apps with path identification still doesn't seem possible.
I wonder if we could make it work by adding something like "query string identification". That wouldn't require re-defining the route since the path is the same, the ID would be passed as a query parameter and used by a middleware.
Netlify should be fixed for the next commit
the ID would be passed as a query parameter and used by a middleware
Sounds like that could work, but I'm not sure
@lukinovec Can you make a BC task for that?