How to get JSON Response on Laravel ?



How to get JSON Response on Laravel ?..

Answer / surbhi

JSON response can be sent using the json method.
This method will automatically set the Content-Type header to application/json.
The json method will automatically convert the array into appropriate json response.

Example :

Route::get('json',function(){
return response()->json(['name' => 'Gandhi', 'state' => 'Gujarat']);
});

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Laravel PHP Framework Interview Questions

Can you exclude uris from csrf protection in laravel? Explain

0 Answers  


What is the service container in laravel?

0 Answers  


What is laravel horizon?

0 Answers  


What is use of laravel?

0 Answers  


What is the difference between laravel and symfony?

0 Answers  






Is laravel spark free?

0 Answers  


Do you know what is routing and how, and what are the different ways to write it?

0 Answers  


Explain me how to assign multiple middleware to laravel route ?

0 Answers  


How to create Controller Laravel - File Uploading ?

1 Answers  


How to use basic routing in laravel?

0 Answers  


What is csrf protection in laravel?

0 Answers  


What is routing and how, and what are the different ways to write it?

0 Answers  


Categories