Laravel - Responses - Json Responses

The json method will automatically set the Content-Type header to application/json, as well as convert the given array to JSON using the json_encode PHP function:

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

If you would like to create a JSONP response, you may use the json method in combination with the withCallback method:

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