<?php

namespace App\Http\Controllers;

use Auth;
use App\Cliente;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ClienteController extends Controller {

    public function __construct() {
        $this->middleware('auth');
    }

    public function listar() {
        #$tipo = Auth::user()->tipo;
        #if ($tipo == 1) {
            #$id = Auth::user()->id;
            #$clientes = Cliente::where('user_id', '=', $id)->get();
            #return view('lista_cliente', compact('clientes'));
        #}
		 $id = Auth::user()->id;
		 $query = "SELECT cliente.* FROM cliente "
                         . " LEFT JOIN users ON cliente.user_id = users.id"
                         . " WHERE empresa_id IN (SELECT id  FROM empresa WHERE user_id = '".$id."')";
		 $clientes = DB::select($query);
		 return view('lista_cliente', compact('clientes'));
    }

}