Add global site settings view composer with database fallback

Implemented view composer in AppServiceProvider to share site settings across all views:
- Loads site name, logo, colors (primary/secondary/accent), and description from Setting model
- Falls back to config/defaults if database unavailable (prevents errors during migrations)
- Made siteSettings available to all Blade templates

Updated layouts and components to use dynamic settings:
- app.blade.php and guest.blade.php now use siteSettings for
This commit is contained in:
2026-03-11 07:37:27 +02:00
parent e274d41f19
commit 4b2ff91ac4
4 changed files with 50 additions and 6 deletions

View File

@@ -2,6 +2,8 @@
namespace App\Providers;
use App\Models\Setting;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@@ -19,6 +21,26 @@ public function register(): void
*/
public function boot(): void
{
//
View::composer('*', function ($view) {
try {
$view->with('siteSettings', [
'name' => Setting::get('site_name', config('app.name', 'Laravel')),
'logo' => Setting::get('site_logo'),
'primary_color' => Setting::get('primary_color', '#3b82f6'),
'secondary_color' => Setting::get('secondary_color', '#8b5cf6'),
'accent_color' => Setting::get('accent_color', '#10b981'),
'description' => Setting::get('site_description'),
]);
} catch (\Exception $e) {
$view->with('siteSettings', [
'name' => config('app.name', 'Laravel'),
'logo' => null,
'primary_color' => '#3b82f6',
'secondary_color' => '#8b5cf6',
'accent_color' => '#10b981',
'description' => null,
]);
}
});
}
}