8

I've this issue in Laravel 5: Class 'App\Http\Controllers\Response' not found. I'm new in all this, so I need your help folks.

I'm trying to get a json response from my table 'funcionarios'. My Controller is:

<? php

namespace App\ Http\ Controllers;

use Illuminate\ Http\ Request;

use App\ Http\ Requests;

use App\ funcionario;

class funcionarioPruebaController extends Controller {
  public
  function index() {

      try {

        $response = [
          'funcionarios' => []
        ];
        $statusCode = 200;
        $funcionario = \App\ funcionario::all() - > take(9);

        foreach($funcionario as $item) {

          $response['funcionarios'][] = [
            'id_funcionario' => $item - > id_funcionario,
            'nombre' => $item - > nombre,
            'apellido' => $item - > apellido,
            'ci' => $item - > ci,
            'rango' => $item - > rango,
            'direccion' => $item - > direccion,
            'telefono' => $item - > telefono

          ];
        }


      } catch (Exception $e) {
        $statusCode = 404;
      } finally {
        return Response::json(array('error' => false, $response, $statusCode));
      }

    } //
}

and my route.php is:

Route::group(array('prefix' => 'xxx'), function() {
  Route::resource('funcionarios', 'funcionarioPruebaController');
});

How can I get all the rows in a json format?

2
  • 9
    use Response; Commented May 2, 2016 at 14:04
  • 2
    Or \Response::json(); Common namespacing issue introduced in Laravel 5+ Commented May 2, 2016 at 14:07

1 Answer 1

11

\Response::json(); Thank you Tim Lewis! You're awesome! :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.