Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'App\Http\Controllers\Response' not found error in Laravel

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?

like image 285
meluluji Avatar asked May 02 '16 14:05

meluluji


1 Answers

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

like image 85
meluluji Avatar answered Oct 19 '22 19:10

meluluji