0

Trying to get the view and put it in array container. I used this code but unfortunately not working:

$data['list'] = User::get();    
return response()->json(['view' => view('table-data', $data), 'count'=>10]);

//output is:
{"view":{},"count":10}
//view is null

I want to get the view and render as $('tbody').html(view); Thanks

2
  • You want to display data in table body right? Commented Sep 22, 2016 at 6:30
  • the data is already rendered in table-data.blade.php, then i want to get that and put it in array container so that i can add more array item that i want. basically i want my html view act as an array value Commented Sep 22, 2016 at 6:33

2 Answers 2

1

There are two ways to return view

1) return view

Syntax :return view('view_name', ['var_name' => 'value']);

Example : return view('table-data',['count'=>10]);

2) return view with compact function

Syntax : return view('view_name', compact('var1','var2','var3'));

Example : return view('table-data',compact('count'));

Sign up to request clarification or add additional context in comments.

Comments

0

Already solved it using view()->render():

return response()->json(['view' => view('table-data', $data)->render(), 'count'=>10]);

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.