<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Exception;
use App\Monedas;
use App\Configuraciones;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {                    
        $test = 1;
        // Test database connection 
        try { 
            \DB::connection()->getPdo();

            
            if (\Schema::hasTable('monedas') & \Schema::hasTable('configuraciones')) {
                $test = 0;
            }else{
                $test = 1; 
            }

        } catch (\Exception $e) { 
            $test = 1; 
        }

        try{
            //$test=1;
            if ($test==0) {

               $auxiliar =  Monedas::all()->where('principal','S')->first();
                view()->share('monedas', Monedas::all()->where('activo','S'));
                view()->share('moneda_principal',$auxiliar);
                view()->share('banner', Configuraciones::find(9));
                view()->share('titulo', Configuraciones::find(7));
                view()->share('descripcion', Configuraciones::find(8));
                $redes = Configuraciones::all()->where('tipo','redes sociales');  
                view()->share('redes',$redes);

                if (session(['moneda_simbolo'])==false or session(['moneda_img'])==false) {                
                    session(['moneda_simbolo' => $auxiliar->simbolo]);
                    session(['moneda_img'     => $auxiliar->bandera]);
                    session(['id_moneda'      => $auxiliar->id]);
                }

            }

        }catch(Exception $error){
            
        }
                
    }
}
