<?php
// app/Providers/SettingsServiceProvider.php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;

class SettingsServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
{
    try {
        // Check if the database connection is established
        if (DB::connection()->getPdo()) {
            // Retrieve settings from the database
            $results = DB::select('SELECT setting_key, setting_value FROM site_settings WHERE deleted_at IS NULL');

            // Pass the settings to all views
            View::share('getSettings', collect($results)->pluck('setting_value', 'setting_key')->all());
        }
    } catch (\Exception $e) {
        // Log any exceptions
        \Log::error('Database connection error: ' . $e->getMessage());
    }
}

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
