/** * Regresa una lista de fideicomisos en JSON * * @return Response */ public function index($query, $page = 0, $size = null) { $query = filter_var($query, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); $total = $size ? $size : self::PAGE_SIZE; // get the results $fields = array_merge($this->string_fields, $this->text_fields); $trusts = Trusts::where(array_shift($fields), 'like', '%' . $query . '%'); foreach ($fields as $field) { $trusts = $trusts->orWhere($field, 'like', '%' . $query . '%'); } $trusts = $trusts->orderBy("id")->groupBy('registry')->skip($page * $total)->take($total)->get(); // get the total $fields = array_merge($this->string_fields, $this->text_fields); $count = Trusts::where(array_shift($fields), 'like', '%' . $query . '%'); foreach ($fields as $field) { $count = $count->orWhere($field, 'like', '%' . $query . '%'); } $count = $count->groupBy('registry')->select("registry")->get()->count(); $response = []; $response['page'] = $page; $response['pages'] = ceil($count / $total); $response['query_total'] = $count; $response['trusts'] = $trusts; return response()->json($response); }
/** * Display a listing of the resource. * * @return Response */ public function index($registry) { // $trusts = Trusts::where('registry', $registry)->orderBy('year', 'asc')->get()->toArray(); if (empty($trusts)) { $trust = Trusts::find($registry)->toArray(); $trusts = [$trust]; } else { $trust = $trusts[0]; } $definitions = Definitions::all(); return view('Gregson', ['trusts' => $trusts, 'selected' => $trust, 'definitions' => $definitions]); }
public function registry(Request $request, $registry = null) { // [ NO SE SELECCIONA NINGÚN REGISTRO ] if (empty($registry)) { // obtiene un registro al azar $registry = Trusts::all()->lists('registry')->random(); // obtiene todos los fideicomisos con el mismo registro $response = Trusts::where('registry', $registry)->select($this->registry_fields)->get(); // los regresa en JSONxCORS return response()->json($response)->header('Access-Control-Allow-Origin', '*'); } else { // separa los registros $list = explode('|', $registry); // obtiene todos los fideicomisos con el mismo registro $response = Trusts::whereIn('registry', $list)->select($this->registry_fields)->get(); // los regresa en JSONxCORS return response()->json($response)->header('Access-Control-Allow-Origin', '*'); } }
public function Categories($name, $page = 0, $category = "branch", $year = 0, $textfields = 0, $full = 0) { $trusts = $year ? Trusts::where("year", $year) : Trusts::where("year", ">", "2000"); if (in_array($category, $this->categories)) { $trusts->where($category, $name); } else { $trusts->where("branch", $name); } $fields = ["id"]; $fields = array_merge($fields, $this->num_fields, $this->string_fields); if ($textfields) { $fields = array_merge($fields, $this->text_fields); } $trusts->select($fields); if (!$full) { $trusts->groupBy('registry'); } $trusts = $trusts->orderBy("id")->skip($page * self::MAX_PAGE_SIZE)->take(self::MAX_PAGE_SIZE)->get(); return response()->json($trusts)->header('Access-Control-Allow-Origin', '*'); }