Mike Thrussell Mike Thrussell - 4 months ago 22
PHP Question

laravel get data from internal get request

My

billingController
returns this from
/billing/total


{"hours":23.25,"distances":209,"durations":3.5}


I want to display this on a dashboard - called by the
homeController


How get a make an internal get request to this data?

Answer

Ideally, you should send AJAX call to that URL, get that data and parse it with Javascript.

If you still want to send request to that URL through another Laravel controller, you should use the following -

$request = Request::create('/billing/total', 'GET');

$response = Route::dispatch($request);

if it is GET request, or

$request = Request::create('/billing/total', 'POST');

$response = Route::dispatch($request);

if it is a POST request.