© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
2 replies
Gandalf

filament.exports.download giving 404 in multi-database multi-tenancy setup

I am using stancl/tenancy for multi database tenancy with filament. I've not enabled tenant features of filament itself, and instead relying on domain based tenancy provided by stancl/tenancy. I'm using the following configuration for tenancy:
  'filesystem' => [
    'suffix_base' => 'tenant/',
    'suffix_storage_path' => true,
    'asset_helper_tenancy' => false,
  ],
  'filesystem' => [
    'suffix_base' => 'tenant/',
    'suffix_storage_path' => true,
    'asset_helper_tenancy' => false,
  ],

In addition I'm using a custom
FileUrlMiddleware
FileUrlMiddleware
with the following in
handle
handle
method:
        config()->set(
            'filesystems.disks.public.url',
            url('/' . config('tenancy.filesystem.suffix_base') . tenant('id'))
        );
        config()->set(
            'filesystems.disks.public.url',
            url('/' . config('tenancy.filesystem.suffix_base') . tenant('id'))
        );

This middleware is being used in
routes/tenant.php
routes/tenant.php
,
config/livewire.php
config/livewire.php
, as well as in the
TenantAdminPanelProvider
TenantAdminPanelProvider


Also, during tenancy creation I'm setting the tenant public paths using a job, as below:
        $this->tenant->run(function ($tenant) {
            $storage_path = storage_path();

            $suffixBase = config('tenancy.filesystem.suffix_base');

            if (!is_dir(public_path($suffixBase))) {
                @mkdir(public_path($suffixBase), 0777, true);
            }

            if (!is_dir($storage_path)) {
                @mkdir("{$storage_path}/app/public", 0777, true);
                @mkdir("{$storage_path}/framework/cache", 0777, true);

                symlink("{$storage_path}/app/public", public_path("{$suffixBase}{$tenant->id}"));
            }
        });
        $this->tenant->run(function ($tenant) {
            $storage_path = storage_path();

            $suffixBase = config('tenancy.filesystem.suffix_base');

            if (!is_dir(public_path($suffixBase))) {
                @mkdir(public_path($suffixBase), 0777, true);
            }

            if (!is_dir($storage_path)) {
                @mkdir("{$storage_path}/app/public", 0777, true);
                @mkdir("{$storage_path}/framework/cache", 0777, true);

                symlink("{$storage_path}/app/public", public_path("{$suffixBase}{$tenant->id}"));
            }
        });


Base on this, all uploads for import are working fine, and data is getting imported alright. Similarly, when I'm trying to export the data, the files are getting created alright, such as:
storage/tenant/0f7a82c3-f357-44f2-86c8-8e49e5bdc18f/app/public/filament_exports/1/0000000000000001.csv
storage/tenant/0f7a82c3-f357-44f2-86c8-8e49e5bdc18f/app/public/filament_exports/1/0000000000000001.csv
which is linked from
public/tenant/0f7a82c3-f357-44f2-86c8-8e49e5bdc18f/filament_exports/1/0000000000000001.csv
public/tenant/0f7a82c3-f357-44f2-86c8-8e49e5bdc18f/filament_exports/1/0000000000000001.csv
thanks to the above code.

However, the path
http://tenant.app.test/filament/exports/1/download?format=csv
http://tenant.app.test/filament/exports/1/download?format=csv
is giving 404.
Solution
Finally managed to solve this by copying the following lines in my
routes/tenant.php
routes/tenant.php
:
    Route::get('/filament/exports/{export}/download', DownloadExport::class)
        ->name('filament.exports.download')
        ->middleware('filament.actions');
    Route::get('/filament/imports/{import}/failed-rows/download', DownloadImportFailureCsv::class)
        ->name('filament.imports.failed-rows.download')
        ->middleware('filament.actions');
    Route::get('/filament/exports/{export}/download', DownloadExport::class)
        ->name('filament.exports.download')
        ->middleware('filament.actions');
    Route::get('/filament/imports/{import}/failed-rows/download', DownloadImportFailureCsv::class)
        ->name('filament.imports.failed-rows.download')
        ->middleware('filament.actions');
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Multi-tenancy panel giving 404
FilamentFFilament / ❓┊help
3y ago
Filament Multi-Tenancy
FilamentFFilament / ❓┊help
15mo ago
Multi tenancy with filament
FilamentFFilament / ❓┊help
2y ago
Multi Tenancy Setup Question
FilamentFFilament / ❓┊help
2y ago