Ejemplo n.º 1
0
 public function index()
 {
     if (Gate::allows('AcessoComerciante')) {
         $usuario = Auth::User();
         $empresa = $usuario->Empresa()->first();
         if (!empty($empresa)) {
             $empresa = $empresa->with('Plano')->with('TipoEmpresa');
             return view('Empresa.Index')->with('empresas', $empresa);
         }
         $empresa = array();
         return view('Empresa.Index')->with('empresas', $empresa);
     } else {
         if (Gate::allows('AcessoAdministrador')) {
             $empresas = Empresa::with('TipoEmpresa')->get();
             return view('Empresa.Index')->with('empresas', $empresas);
         }
     }
     return view('401');
 }
Ejemplo n.º 2
0
 public function filtroEmpresas($filtros = null)
 {
     //        dd($filtros);
     $local_url = Input::get("local");
     //apenas um
     $servicos_url = Input::get("com");
     //um ou varios
     $tipo_url = Input::get("tipo");
     //comercios,servicos,atracoes,profissionais
     //        $query_empresa = Input::get("pesquisaEmpresa");
     //        $query_endereco = Input::get("pesquisaEndereco");
     $busca_url = Input::get("pesquisaEmpresa");
     //busca de empresas
     $endereco_url = Input::get("pesquisaEndereco");
     //busca de endereço
     $categoria_url = null;
     $subcategoria_url = null;
     if ($filtros) {
         $filtros = explode('/', $filtros);
         if (sizeof($filtros) > 0) {
             $categoria_url = $filtros[0];
         }
         if (sizeof($filtros) == 2) {
             $subcategoria_url = $filtros[1];
         }
     }
     //        dd("LOCAL = ".$local,"SERVICOS = ".$servicos,"CATEGORIA = ".$categoria, "SUBCATEGORIA = ".$subcategoria,"TIPO DA EMPRESA = ".$tipo);
     $categorias = Categoria::whereNull('idCategoriaPai')->orderBy('nome', 'asc')->lists('nome', 'id')->all();
     $subcategorias = Categoria::where('idCategoriaPai', '!=', '')->orderBy('nome', 'asc')->lists('nome', 'id')->all();
     $servicos_selecionados_id = array();
     if ($servicos_url != null) {
         $servicos_slug = explode(",", $servicos_url);
         foreach ($servicos_slug as $servico_slug) {
             $servicos_selecionados_id[] = Servico::where('slug', $servico_slug)->first()->id;
         }
     }
     $servicos = Servico::orderBy('descricao', 'asc')->lists('descricao', 'id')->all();
     //Todo: busca de empresas pelos parâmetros informados na url
     //EX: http://localhost:8000/Empresas/restaurantes/pizzarias?com=wi-fi,seguranca&local=sp&tipo=comercios
     //        $empresas = Empresa::where();
     //$query = DB::table('empresas');
     if ($subcategoria_url != null) {
         $subcategoria_id = Categoria::where('slug', $subcategoria_url)->first()->id;
     } else {
         if ($categoria_url != null) {
             $categoria_id = Categoria::where('slug', $categoria_url)->first()->id;
         }
     }
     //        $empresas_por_categoria = CategoriaEmpresa::where('idCategoria', $categoria_id)->get();
     //        dd($empresas_por_categoria);
     /*if ($state_id != '--')
       {
           $query->where('state_id', '=', $state_id);
       }*/
     //        $empresas = $query->orderBy('nomeFantasia')->get();
     $empresas = Empresa::with('CategoriaEmpresa')->with('CategoriaEmpresa.Categoria')->with('TipoCartao')->get();
     //        dd($empresas);
     return view('index')->with('busca_url', $busca_url)->with('endereco_url', $endereco_url)->with('empresas', $empresas)->with('tipo', $tipo_url)->with('categorias', $categorias)->with('subcategorias', $subcategorias)->with('servicos', $servicos)->with('servicos_selecionados_id', $servicos_selecionados_id);
 }