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

Tell me what are pros and cons of using laravel framework?

548


How do I setup localization for an application?

541


What is eloquent orm in laravel?

538


How do I assign several roles to users and permit the users to perform some actions based on those roles?

505


Explain request life cycle of laravel.

595


What is a Terminable Middleware ?

679


Define implicit controller.

549


Is laravel support caching? Explain

547


Why should I use laravel?

519


Tell me is laravel an open source?

529


What is a Laravel - Authentication ?

860


what is Basic Routing ?

1308


What is a check method ?

851


How to get last inserted id using laravel query?

572


How to start, stop mysql on valet?

519