How to properly display the data in the template?

0 like 0 dislike
4 views
Obivious Laravel Ohm for 3 day.
At the moment the database is stored here is the answer:
[["c"],["b"],["a"],["a"],["c"],["b"],["b"],["b"],["c"],["a"],["b"],["b"],["c"],["c"],["c"],["c"],["b"],["b"],["b"],["a"],["c"],["c"],["c"],["c"],["a"],["c"],["c"],["a"],["a"],["a"],["b"],["a"],["b"],["b"],["b"],["a"],["a"],["a"],["b"],["b"],["b"],["a"],["c"],["b"],["a"],["b"],["b"],["a"],["c"],["b"],["b"],["b"],["a"],["a"],["b"],["c"],["a"],["c"],["a"],["a"],["b"],["b"],["c"],["a"],["a"],["c"],["c"],["a"],["a"],["b"],["c"],["b"],["a"],["b"],["c"],["b"],["b"]]

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
https://laravel.ru/docs/v5/eloquent-mutators#%D0%B...

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()

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

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

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
0 comments
33,911 users