【问题标题】:Class 'App\Http\Controllers\Response' not found error in Laravel在 Laravel 中找不到类“App\Http\Controllers\Response”错误
【发布时间】:2016-08-27 07:59:26
【问题描述】:

我在 Laravel 5 中有这个问题:Class 'App\Http\Controllers\Response' not found。我是这一切的新手,所以我需要你们的帮助。

我正在尝试从我的表 'funcionarios' 中获取 json 响应。 我的控制器是:

<? 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));
      }

    } //
}

而我的 route.php 是:

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

如何获取 json 格式的所有行?

【问题讨论】:

  • use Response;
  • \Response::json(); Laravel 5+ 中引入的常见命名空间问题

标签: php json laravel-5.1


【解决方案1】:

\Response::json(); 谢谢蒂姆·刘易斯!你真棒! :)

【讨论】:

    猜你喜欢
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 2018-01-03
    • 1970-01-01
    • 2017-08-05
    • 2015-07-12
    相关资源
    最近更新 更多