Laravel json response from controller example

By Hardik Savani | May 11, 2016 | Category : Laravel

If you are working with REST API then you always need to return json data response that way front-end developer can handle it easily. i created bellow controller method in this method i return json array response, that way you can understand very well. laravel 5 provide response() helper and it will help to response of json object. But if you are working on Core PHP then you have to do json_encode before send output. In laravel you can do it easily like this way:


public function getJsonData()


$myArray = ['id'=>1, 'name'=>'HD'];

return response()->json($myArray);


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.