How to get JSON Response on Laravel ?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain me how to assign multiple middleware to laravel route ?

606


Explain the difference between laravel and codeigniter?

532


How do I see all of the routes that are defined?

521


What is the purpose of using dd() function iin laravel?

521


How to assign a variable value for all view file?

498


Is laravel easier than php?

516


What are the applications supported by valet?

496


What are the differences between laravel and codeigniter?

566


Define http middleware?

557


What is difference between single quote and double quote?

491


What is composer in laravel?

544


What is composer lock in laravel?

514


What is escape string?

550


Explain how to install installing mariadb on homestead?

547


How can you update homestead?

592