<?php

namespace App\Lib;

class Util
{
    public function filterList($entity, $request){
    
        $id = $entity->getKeyName();
        $where = $request->query('where');
        $orderBy = $request->query('orderBy');
        $orderType = $request->query('orderType');
        $limit = $request->query('limit');
       

        if($where && $where == 'yes'){
            foreach ($request->query as $clave => $valor){
                if ($clave != 'where' and $clave != 'orderBy' and $clave != 'orderType' and $clave != 'limit' and $clave != 'page') {
                    $entity = $entity->whereIn($clave, explode(",",str_replace(array("[", "]"), '', $valor)));
                }
            }
        }

       

      /* if($limit){
            $entity = $entity->paginate($limit);
        } else {
            $entity = $entity->paginate(config("constants.LIMIT_DEFAULT"));
        }*/
        
        $entity = $entity->get();
    
        return $entity;
    }
}
