livewire icon indicating copy to clipboard operation
livewire copied to clipboard

allow to overwrite default web middleware for file uploads

Open marianperca opened this issue 2 years ago • 2 comments

This PR allows to override the default web middleware for applications were this doesn't exist, specifically for multi-tenant setups.

1️⃣ Is this something that is wanted/needed? Did you create a discussion about it first? Yes, customisation of the middleware is wanted.

2️⃣ Did you create a branch for your fix/feature? (Main branch PR's will be closed) Yes

3️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out. No

4️⃣ Does it include tests? (Required) Yes

5️⃣ Please include a thorough description (including small code snippets if possible) of the improvement and reasons why it's useful.

For multi-tenant apps, the web middleware might not be present, at least in the implementation I'm using it's not. This poses an issue when uploading files, as the web middleware is applied automatically and can't be overwritten using the config. In my previous PR #8905 you suggested to add a new config, but I think the majority of users won't need this, and adding a new default in config is not needed. The same approach was used for https://github.com/livewire/livewire/blob/3c8d1f9d7d9098aaea663093ae168f2d5d2ae73d/src/Features/SupportFileUploads/FilePreviewController.php#L11 that was introduced in #7911. Since using a static variable, overriding the default middleware can be made in a service provider:

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        FileUploadController::$default_middleware = 'tenant';
        ...
    }

If you think it's beneficial to have a new config value for this, I'll update the code. Thank you!

marianperca avatar Oct 21 '24 09:10 marianperca

Is this not a duplicate of #8930?

lrljoe avatar Oct 22 '24 02:10 lrljoe

@lrljoe there's a test and now the default middleware is a string, not an array. Also the code is updated to work with #8931.

marianperca avatar Oct 22 '24 04:10 marianperca

This would definitely need documentation writing for it.

lrljoe avatar Nov 08 '24 06:11 lrljoe

sounds good, thanks!

calebporzio avatar May 29 '25 21:05 calebporzio