Laravel JSON response returns protected data

return Response::json(array('status' => 'Group not found'));

returns protected data. Here's the JSON:

{"status":"Group not found"}

Following code

//$jsonData - the data returned above

var_dump($jsonData);

returns this:

object (Illuminate \ Http \ JsonResponse) # 320 (10) {["jsonOptions": protected] => int (0) ["data": protected] => string (28) "{" status ":" Group not found "}" ["callback": protected] => NULL ["encodingOptions": protected] => int (15) ["headers"] => object (Symfony \ Component \ HttpFoundation \ ResponseHeaderBag) # 317 (5) {[ "compulatedCacheControl": protected] => array (1) {["no-cache"] => bool (true)} ["cookies": protected] => array (0) {} ["headerNames": protected] = > array (3) {["cache-control"] => string (13) "Cache-Control" ["content-type"] => string (12) "Content-Type" ["date"] => string (4) "Date"} ["headers": protected] => array (3) {["cache-control"] => array (1) {[0] => string (8) "no-cache"} ["content-type" ] => array (1) {[0] => string (16) "application / json"} ["date"] => array (1) {[0] => string (29) "Tue, June 17, 2014 19:03:33 GMT "}} [" cacheControl ": protected] => array (0) {}} [" content ": protected] => string (28)" {"status": "Group not found"} "[" version ": protected] => string (3)" 1.0 "[" statusCode ": protected] => int (200) [" statusText ": protected] => string (2)" OK "[" charset " : protected] => NULL}array (1) {[0] => string (8) "no-cache"} ["content-type"] => array (1) {[0] => string (16) "application / json"} [ "date"] => array (1) {[0] => string (29) "Tue, Jun 17, 2014 7:03:33 PM GMT"}} ["cacheControl": protected] => array (0) {} } ["content": protected] => string (28) "{" status ":" Group not found "}" ["version": protected] => string (3) "1.0" ["statusCode": protected] => int (200) ["statusText": protected] => string (2) "OK" ["charset": protected] => NULL}array (1) {[0] => string (8) "no-cache"} ["content-type"] => array (1) {[0] => string (16) "application / json"} [ "date"] => array (1) {[0] => string (29) "Tue, Jun 17, 2014 7:03:33 PM GMT"}} ["cacheControl": protected] => array (0) {} } ["content": protected] => string (28) "{" status ":" Group not found "}" ["version": protected] => string (3) "1.0" ["statusCode": protected] => int (200) ["statusText": protected] => string (2) "OK" ["charset": protected] => NULL}] => array (1) {[0] => string (29) "Tue, Jun 17, 2014 7:03:33 PM GMT"}} ["cacheControl": protected] => array (0) {}} [" content ": protected] => string (28)" {"status": "Group not found"} "[" version ": protected] => string (3)" 1.0 "[" statusCode ": protected] => int (200) ["statusText": protected] => string (2) "OK" ["charset": protected] => NULL}] => array (1) {[0] => string (29) "Tue, Jun 17, 2014 7:03:33 PM GMT"}} ["cacheControl": protected] => array (0) {}} [" content ": protected] => string (28)" {"status": "Group not found"} "[" version ": protected] => string (3)" 1.0 "[" statusCode ": protected] => int (200) ["statusText": protected] => string (2) "OK" ["charset": protected] => NULL}protected] => int (200) ["statusText": protected] => string (2) "OK" ["charset": protected] => NULL}protected] => int (200) ["statusText": protected] => string (2) "OK" ["charset": protected] => NULL}

["data":protected]=> string(28) "{"status":"Group not found"}". - JSON. " " ( )?

+4
1

, .

:

\Symfony\Component\HttpFoundation\Response
    \Symfony\Component\HttpFoundation\JsonResponse
        \Illuminate\Http\JsonResponse

:

public function __toString()
{
    ...
    return ... . $this->getContent();
}

, :

public function getContent()
{
    return $this->content;
}

, protected $content, , JsonResponse , PHP __toString() .

+6

Source: https://habr.com/ru/post/1544979/


All Articles