diff --git a/src/Controllers/TenantAssetsController.php b/src/Controllers/TenantAssetsController.php new file mode 100644 index 00000000..8f2aa6a4 --- /dev/null +++ b/src/Controllers/TenantAssetsController.php @@ -0,0 +1,23 @@ +middleware('tenancy'); + } + + public function asset($path) + { + try { + return response()->file(storage_path('app/public/' . $path)); + } catch (\Throwable $th) { + dd(storage_path('app/public/' . $path)); + abort(404); + } + } +} diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index fa49ab0c..c3636189 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -33,6 +33,8 @@ class TenancyServiceProvider extends ServiceProvider $this->publishes([ __DIR__ . '/config/tenancy.php' => config_path('tenancy.php'), ], 'config'); + + $this->loadRoutesFrom(__DIR__ . '/routes.php'); } /** diff --git a/src/helpers.php b/src/helpers.php index a2769c2c..09ba118f 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -13,9 +13,16 @@ if (! function_exists('tenancy')) { } } -if (!function_exists('tenant')) { +if (! function_exists('tenant')) { function tenant($key = null) { return tenancy($key); } } + +if (! function_exists('tenant_asset')) { + function tenant_asset($asset) + { + return route('stancl.tenancy.asset', ['asset' => $asset]); + } +} diff --git a/src/routes.php b/src/routes.php new file mode 100644 index 00000000..a51a8871 --- /dev/null +++ b/src/routes.php @@ -0,0 +1,5 @@ +where('path', '(.*)') + ->name('stancl.tenancy.asset');