Connect with us


how to use json response in laravel

php framework

how to use json response in laravel

how to use json response in laravel










JSON Responses
Laravel provides a Response::json() method that will configure the response object with a number
of details that are specific to JSON results.
For example an appropriate HTTP Content-Type header.
We could set these up manually, but why bother when Laravel will do it for us? Let’s have a look at
this method in action.

// app/routes.php

Route::get(‘markdown/response’, function()
$data = array(‘first’, ‘second’, ‘third’,’fourth’);
return Response::json($data);
By handing an array to the Response::json() method it has been converted to a JSON string and
set as the body of our new Response object. Appropriate headers have been set to explain that the
provided data is infact a JSON string. The web browser will receive the following body:
{first’, ‘second’, ‘third’,’fourth’}

fast json retrievel from json data by using laravel .

for more go to laravel

More in php framework


To Top