How to properly display the data in the template?

0 like 0 dislike
Obivious Laravel Ohm for 3 day.
At the moment the database is stored here is the answer:

I put it there this way:
Answer::create([ 'name' => $request->name, 'answer' => json_encode($answers), // Here it is 'a' => $answer_a, 'b' => $answer_b, 'c' => $answer_c, ]);

How do I now pass in the form that it was possible to access each cell ?
Tried so
$name = Answer::select('name')->get(); $answers = json_decode(Answer::select('answer')->get()[0], true); return view('home')->with(['name' => $name, 'answers' => $users]);

To html tried so
{{ $answers[3] }}
The result obtained on each character, because the first bracket then the bracket, quote etc
How do I implement this all ? 5ae346e850514234969898.png
Like this table.
Data will be updated and you want to display info in the admin area.....
by | 4 views

1 Answer

0 like 0 dislike

To execute the json_encode and json_decode is not required.

in this line
$answers = json_decode(Answer::select('answer')->get()[0], true);

you get an instance of a model is not the answer. First it is necessary to get rid of json_decode, and secondly, the required field you will be in $answers->answer

Debug code to understand what is in your variables, use the debugger or dump, using the dump() and dd()

return view('home')->with(['name' => $name, 'answers' => $users]);

return view('home', ['name' => $name, 'answers' => $users]);

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
33,911 users