lundi 2 mai 2016

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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire