1

I want to make this, 1. Controller return json data to view

$data =  Response::json(array('status' => FALSE, 'code' => 205, 'message' => 'Deneme', 'data' => null), 200 );

    return View::make('site.index.index')->with('data', $data);

2. view will make decode this data and will use.

{{ $data2 = @json_decode($data)  }}

{{ var_dump($data2) }}

json data going into view but don't decoding on array.

How can decode this data?

2
  • Response::json is meant to be the actual response returned by the controller (see laravel.com/docs/4.2/responses#special-responses), instead you have passed that response through to the view as data. It might help to clarify why you are using the json encoding step, instead of $data = array('status' => FALSE, 'code' => 205, 'message' => 'Deneme', 'data' => null), 200 ); and then {{ var_dump($data) }}. Commented Mar 21, 2015 at 0:23
  • Why do you want to decode json in the view? When you add data to viewbag, it should be already decoded, prepared and ready to place in the template. Template is not a place for data logic. Commented Feb 27, 2016 at 10:24

1 Answer 1

1
$data = json_encode(array('status' => FALSE, 'code' => 205, 'message' => 'Deneme', 'data' => null));

return View::make('site.index.index')->with('data', $data);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.