find(Banco::class)->array(); if ($bancos) { usort($bancos, function($a, $b) { return strcmp($a['nombre'], $b['nombre']); }); } $output = [ 'bancos' => $bancos ]; return $this->withJson($response, $output); } public function show(Request $request, Response $response, Factory $factory, $banco_id): Response { $banco = $factory->find(Banco::class)->one($banco_id); $output = [ 'input' => $banco_id, 'banco' => $banco?->toArray() ]; return $this->withJson($response, $output); } public function add(Request $request, Response $response, Factory $factory): Response { $input = json_decode($request->getBody()); $results = []; if (is_array($input)) { foreach ($input as $in) { $banco = Banco::add($factory, $in); $results []= ['banco' => $banco?->toArray(), 'agregado' => $banco?->save()]; } } else { $banco = Banco::add($factory, $input); $results []= ['banco' => $banco?->toArray(), 'agregado' => $banco?->save()]; } $output = [ 'input' => $input, 'bancos' => $results ]; return $this->withJson($response, $output); } public function edit(Request $request, Response $response, Factory $factory, $banco_id): Response { $banco = $factory->find(Banco::class)->one($banco_id); $output = [ 'input' => $banco_id, 'old' => $banco->toArray() ]; $input = json_decode($request->getBody()); $banco->edit($input); $output['banco'] = $banco->toArray(); return $this->withJson($response, $output); } public function delete(Request $request, Response $response, Factory $factory, $banco_id): Response { $banco = $factory->find(Banco::class)->one($banco_id); $output = [ 'input' => $banco_id, 'banco' => $banco->toArray(), 'eliminado' => $banco->delete() ]; return $this->withJson($response, $output); } }