[英]Laravel: How to get the json response from API
This is the response returned from one of my controllers 这是我的一个控制器返回的响应
class initController extends Controller
{
public function index(Request $request)
{
$init=DB::table('inits')->select('authID')->inRandomOrder()->first();
if($init == false){
return response()->json(['status:' => 1 ,'authID' => current($init)]);
}
return response()->json(['status:' => 0 ,'authID' => current($init)]);
}
}
This is the API route 这是API路线
Route::get('init', 'initController@index');
Route::get('getLargeImage', 'getLargeImageController@getImg');
This is the getLargeImage contoller 这是getLargeImage contoller
class getLargeImageController extends Controller
{
public function index()
{
}
}
Now, in this controller how can I get the json response from the first one? 现在,在此控制器中,如何从第一个响应中获取json响应?
I think a simple Google search would suffice; 我认为简单的Google搜索就足够了。 https://laravel-tricks.com/tricks/internal-requests
https://laravel-tricks.com/tricks/internal-requests
There are many articles on making internal requests on Laravel, and also, this question has been asked and answered previously here, eg; 有许多关于Laravel提出内部请求的文章,而且,此问题先前已在此处提出和回答,例如; Consuming my own Laravel API
消耗我自己的Laravel API
To answer your question, you make an internal request base on your route; 为了回答您的问题,您会根据自己的路线提出内部要求;
$request = Request::create('init', 'GET');
$response = Route::dispatch($request);
You can try this, 你可以试试看
class getLargeImageController extends Controller
{
public function index(Request $request)
{
$response = app('App\Http\Controllers\initController')->index($request);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.