Laravel json response code example

Example 1: php laravel return json response

return response()->json([
    'name' => 'Abigail',
    'state' => 'CA'
]);

Example 2: response()->json(['data' => $allCheaters]) not getting back

return response()->json(['name' => 'Abigail', 'state' => 'CA']);

Example 3: laravel json response

return response()->json([
    'name' => 'Abigail',
    'state' => 'CA',
]);

Example 4: laravel json response with error code

return Response::json([
    'hello' => $value
], 201); // Status code here

Example 5: Laravel json response

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

Tags:

Php Example