10-Apr-2023
.
Admin
This tutorial shows you laravel 9 return json from controller. This article will give you simple example of laravel 9 return json data. Here you will learn laravel 9 response json array. This post will give you simple example of laravel 9 json response status code. Here, Creating a basic example of laravel 9 json response example.
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:
Let's start following example:
Example:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class JsonController extends Controller
{
/**
* Json Response a new controller instance.
*
* @return void
*/
public function getJsonData()
{
$myArray = ['id'=>1, 'name'=>'johnson'];
return response()->json($myArray);
}
}
It will help you...
#Laravel 9
#Laravel