Laravel json response from controller example

Laravel json response from controller example

In this post we will give you information about Laravel json response from controller example. Hear we will give you detail about Laravel json response from controller exampleAnd how to use it also give you demo for it if it is necessary.

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:

Example:

public function getJsonData()

{

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

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

}

Hope this code and post will helped you for implement Laravel json response from controller example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  67  =  73

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US