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 with the following in 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, config/livewire.php, as well as in the 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 which is linked from 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 is giving 404.
Solution:
Finally managed to solve this by copying the following lines in my routes/tenant.php: ```php Route::get('/filament/exports/{export}/download', DownloadExport::class) ->name('filament.exports.download') ->middleware('filament.actions');...
Jump to solution
1 Reply
Solution
Gandalf
Gandalf7mo ago
Finally managed to solve this by copying the following lines in my 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');
Want results from more Discord servers?
Add your server