<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Response;
use App\Services\ConexService;
use App\Modules\System\Models\Menu;
use View;
use Auth;
use Session;
class ConexCustomService extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('App/Services/ConexService', function ($app) {
            return new ConexService();
        });  
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $path = base_path('install.txt');
     
        if (file_exists($path)) {
            Auth::logout();
            Session::flush();
           if (request()->is('install*')) {
                # code...
            }else{

                redirect('install')->send();
            }
        }else{
            try { 
                DB::connection()->getPdo(); 
                view()->share('menus', Menu::menus());
              } catch (\Exception $e) {
                Auth::logout();
                Session::flush();
                View::share('errordb', '1');
                if (request()->is('error*')) {
                    # code...
                }else{
                    redirect('error/')->send();
                }
            }
        }
    }
}
