public function parseFilter($campo, $valor, $query)
 {
     //se verifica si hay que buscar en otras tablas
     if (str_contains($campo, '->')) {
         $arrayOps = explode('->', $campo);
         //relacion sencilla
         if (count($arrayOps) == 2) {
             $tabla = str_plural_spanish(explode('.', $arrayOps[0])[1]);
             $campo = $tabla . '.' . $arrayOps[1];
         } else {
             if (count($arrayOps) == 3) {
                 $tabla = str_plural_spanish($arrayOps[1]);
                 $campo = $tabla . '.' . $arrayOps[2];
             }
         }
     }
     //arrays aplica whereIn, integer aplica =, strings aplica like %..%, fechas aplica >= o <= y se convierten en carbon
     try {
         $fecha = \Carbon::createFromFormat('d/m/Y', $valor);
         $esfecha = true;
     } catch (\Exception $e) {
         $esfecha = false;
     }
     if ($esfecha) {
         $operador = str_contains($campo, '_desde') ? '>=' : '<=';
         $campo = str_replace('_desde', '', $campo);
         $campo = str_replace('_hasta', '', $campo);
         $query->where($campo, $operador, $fecha);
     } else {
         if (is_array($valor)) {
             $query->whereIn($campo, $valor);
         } else {
             if (is_numeric($valor)) {
                 $query->where($campo, $valor);
             } else {
                 if (is_string($valor)) {
                     //Se usa i like para que sea insensible a mayusculas
                     $query->where($campo, 'ILIKE', '%' . $valor . '%');
                 }
             }
         }
     }
     return $query;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $namespace = "Tablas";
     //borrramos generaciones previas
     File::deleteDirectory(app_path('contraladores_generados'));
     //creamos el directorio en app..
     File::makeDirectory(app_path('contraladores_generados'), 777);
     $this->info("Buscando modelos");
     $models = File::files(app_path('models'));
     foreach ($models as $model) {
         if (File::isFile($model)) {
             $baseText = File::get(app_path('controllers/templates/Template.txt'));
             $controllerName = str_plural_spanish(str_replace('.php', '', basename($model))) . 'Controller';
             $this->info("Generando controller: " . $controllerName);
             //replace class name..
             $baseText = str_replace('@class_name@', $controllerName, $baseText);
             //replace namespace..
             $baseText = str_replace('@namespace@', $namespace, $baseText);
             File::put(app_path('contraladores_generados/' . $controllerName . '.php'), $baseText);
         }
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //borrramos generaciones previas
     File::deleteDirectory(app_path('vistas_generadas'));
     //creamos el directorio en app..
     File::makeDirectory(app_path('vistas_generadas'), 777);
     $this->info("Buscando modelos");
     $models = File::files(app_path('models'));
     foreach ($models as $model) {
         if (File::isFile($model)) {
             $modelName = str_replace('.php', '', basename($model));
             if ($modelName != 'BaseModel') {
                 $modelInstance = new $modelName();
                 $collectionName = lcfirst(str_plural_spanish($modelName));
                 $baseText = File::get(app_path('controllers/templates/View.txt'));
                 $baseText = str_replace('@model_name@', $modelName, $baseText);
                 $baseText = str_replace('@pretty_name@', $modelInstance->getPrettyName(), $baseText);
                 $baseText = str_replace('@collection_name@', $collectionName, $baseText);
                 $basePath = app_path('vistas_generadas');
                 $this->info("Generando vista: " . $collectionName);
                 File::put($basePath . '/' . $collectionName . '.blade.php', $baseText);
                 $baseText = File::get(app_path('controllers/templates/Form.txt'));
                 $baseText = str_replace('@var_name@', lcfirst($modelName), $baseText);
                 $baseText = str_replace('@pretty_name@', $modelInstance->getPrettyName(), $baseText);
                 $baseText = str_replace('@collection_name@', $collectionName, $baseText);
                 $fieldsStr = "";
                 $fields = $modelInstance->getFillable();
                 foreach ($fields as $key) {
                     $fieldsStr .= "{{Form::btInput(\$" . lcfirst($modelName) . ", '" . $key . "', 6)}}" . PHP_EOL;
                 }
                 $baseText = str_replace('@fields@', $fieldsStr, $baseText);
                 $basePath = app_path('vistas_generadas');
                 $this->info("Generando formulario: " . $collectionName);
                 File::put($basePath . '/' . $collectionName . 'form.blade.php', $baseText);
             }
         }
     }
 }
 public function getCollectionName()
 {
     if (is_null($this->collectionName)) {
         $modelName = $this->getModelName();
         $this->collectionName = lcfirst(str_plural_spanish($modelName));
     }
     return $this->collectionName;
 }