<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use user;
use ref_manzanillo;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index(Request $request)
    {
        if(Auth::check()){
            if($request->user()->hasRole('Administrador') || $request->user()->hasRole('Estandar')){

                // $MZ = DB::table('referencias_mz')-paginate(20);
                // $MX = DB::select('SELECT * FROM referencias_mx');
                // $LZ = DB::select('SELECT * FROM referencias_lz');
                // $VZ = DB::select('SELECT * FROM referencias_vz');
                $MZ = ref_manzanillo::orderBy('id', 'Desc')->name($request->GET('ref'))->paginate(20);

                $id = auth()->user()->id;
                $datos = DB::connection('usuariosMysql')->select("select * from vw_list_user WHERE id = '".$id."'");
                $Clnts = DB::connection('clientesMysql')->select('SELECT * FROM clientes_MZ');
                return view('referencias.v_listaReferencias', compact('datos', /*'LZ' , 'VZ', 'MX',*/ 'MZ', 'Clnts'));

            }else {
                return redirect()->route('login');
            }
        }else {
            return redirect()->route('login');
        }
    }
}