public function getCostumers() { //if( Request::ajax() ){ $query = Input::get('query'); $clientes = Cliente::where('nome', 'like', '%' . $query . '%')->orWhere('empresa', 'like', '%' . $query . '%')->get(); $fornecedores = Fornecedor::where('nome', 'like', '%' . $query . '%')->orWhere('empresa', 'like', '%' . $query . '%')->get(); $vendedores = Vendedor::where('nome', 'like', '%' . $query . '%')->orWhere('empresa', 'like', '%' . $query . '%')->get(); foreach ($clientes as $cliente) { $suggestions[] = array("value" => $cliente->nome . " [" . $cliente->empresa . "]", "data" => array('type' => 'Clientes (' . count($clientes) . ')', 'obj' => json_encode($cliente))); } foreach ($fornecedores as $fornecedor) { $suggestions[] = array("value" => $fornecedor->nome . " [" . $fornecedor->empresa . "]", "data" => array('type' => 'Fornecedores (' . count($fornecedores) . ')')); } foreach ($vendedores as $vendedor) { $suggestions[] = array("value" => $vendedor->nome . " [" . $vendedor->empresa . "]", "data" => array('type' => 'Vendedores (' . count($vendedores) . ')')); } $costumers = array('suggestions' => $suggestions); //$costumers = Cliente::all(); return Response::json($costumers); //} }
public function getContacts() { //if( Request::ajax() ){ $query = Input::get('query'); $clientes = Cliente::where('email', 'like', '%' . $query . '%')->get(); $fornecedores = Fornecedor::where('email', 'like', '%' . $query . '%')->get(); $vendedores = Vendedor::where('email', 'like', '%' . $query . '%')->get(); foreach ($clientes as $cliente) { $suggestions[] = array("value" => $cliente->email, "data" => array('type' => 'Clientes (' . count($clientes) . ')')); } foreach ($fornecedores as $fornecedor) { $suggestions[] = array("value" => $fornecedor->email, "data" => array('type' => 'Fornecedores (' . count($fornecedores) . ')')); } foreach ($vendedores as $vendedor) { $suggestions[] = array("value" => $vendedor->email, "data" => array('type' => 'Vendedores (' . count($vendedores) . ')')); } $contacts = array('suggestions' => $suggestions); //$contacts = Cliente::all(); return Response::json($contacts); //} }