dpftppc9674 2017-04-20 09:12
浏览 317
已采纳

如何在laravel中从内部api请求获取json响应?

My route file (routes/api.php) :

Route::group(['middleware'=>'cors', 'prefix'=>'v1/'], function(){
    Route::resource('users', 'UserController');
    Route::resource('products', 'ProductController');
    Route::resource('categories', 'CategoryController');

    Route::resource('authenticate', 'AuthenticateController', ['only' => ['index']]);
    Route::post('authenticate', 'AuthenticateController@authenticate');
    Route::get('authenticate/user', 'AuthenticateController@getAuthenticatedUser');
});

My ProductController file():

public function index(){
    $request = Request::create('api/v1/products/', 'GET');
    $instance = json_decode(Route::dispatch($request)->getContent());
    echo "<pre>"; print_r($instance); exit;

    return view('pages.users.my_sell', ['products'=>$products]); 
}

while i try to print the $instance variable i get the following error : enter image description here

i need to get all the object from the api and need to pass the objects to my blade.

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 关于#c++#的问题:用C++编程实现主存-Cache地址映射(附运行成功截图+注释)
      • ¥25 接口/特征方法的异常错误返回如何判断是否需要设计
      • ¥40 代码+预测分析,文件私信发哦(价格可商量)
      • ¥15 GAMES101 HW1 无法定义
      • ¥15 pycharm不管允许什么代码都出错,都会出现下面的情况。
      • ¥15 boost::integrate的用法
      • ¥20 51单片机输出pwm时无法调节频率,如何解决?
      • ¥15 DSP28335 AD采集正弦波
      • ¥50 pwwinauto调式修改
      • ¥30 关于#单片机#的问题:单片机基于51单片机开发计时器,使其实现以下功能:(1)开发板上四个独立按键分别控制计时器的启停、计时器的复位(按下计时值归零)、计时位切换、计时时间的递增