database = $database; } public function handle(Request $request, ConnectionInterface $httpConnection) { $this->database->query('SELECT * FROM users ORDER by created_at DESC')->then(function (Result $result) use ($httpConnection) { $httpConnection->send( respond_html($this->getView(['users' => $result->rows])) ); $httpConnection->close(); }, function (\Exception $exception) use ($httpConnection) { $httpConnection->send(respond_html('Something went wrong: '.$exception->getMessage(), 500)); $httpConnection->close(); }); } protected function getView(array $data) { $twig = new Environment( new ArrayLoader([ 'template' => file_get_contents(base_path('resources/views/admin/users/index.twig')), ]) ); return stream_for($twig->render('template', $data)); } }