/** * Bootstrap the application services. * * @return void */ public function boot() { if (!$this->app->routesAreCached()) { require_once __DIR__ . '/routes.php'; } require_once __DIR__ . '/Helpers/helpers.php'; $this->registerTenant(); if ($tenant = tenant()) { $directory = tenant_path($tenant); // Load views from the current tenant directory $this->app['view']->addLocation(realpath($directory . '/views')); // Load the tenant routes within the application controller namespace. if (file_exists($directory . '/routes.php')) { Route::group(['namespace' => 'App\\Http\\Controllers'], function () use($directory) { require_once $directory . '/routes.php'; }); } // Set the tenant cache driver Cache::setDefaultDriver('friet-nl'); } // Load base views, these will be overridden by tenant views with the same name $this->app['view']->addLocation(realpath(base_path('resources/views'))); // Publish the tenant config, which will be overriden by local configuration $this->publishes([__DIR__ . '/../config/tenant.php' => config_path('tenant.php')], 'multi-tenant'); }
/** * Get the route to retrieve the given tenant asset. * * Uses a fallback to load the asset from the default * directory in case the tenant asset doesn't exist. * * @param string $path * @param bool $secure * @return string */ function tasset($path, $secure = null) { $tenant = tenant(); $asset = tenant_path($tenant, '/assets/' . $path); if ($tenant && file_exists($asset)) { return route('asset', [$path]); } return asset($path, $secure); }
<?php /** * Load tenant assets outside the public folder with this route. */ Route::get('asset/{path}', ['as' => 'asset', function ($path) { $asset = tenant_path(tenant(), '/assets/' . $path); if (!file_exists($asset)) { abort(404); } $mime = File::mimeType($asset); if ($mime == 'text/plain' && File::extension($asset) == 'css') { $mime = 'text/css'; } return response(file_get_contents($asset), 200, ['Content-Type' => $mime]); }])->where('path', '(.*)');