如何在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.

In your controller, have you included this?

use \Illuminate\Support\Facades\Route;

You're doing it wrong. If you do not want to repeat Eloquent code, just create a getAllPproducts() method in the model and use it in controller methods:

public function index()
{
    return view('pages.users.my_sell', [ 
        'products' => $this->product->getAllProducts()
    ]); 
}

Just an example of getAllProducts():

public function getAllProducts()
{
    return $this->paginate(20);
}