Answer the question
In order to leave comments, you need to log in
How to correctly display data in the template?
I've been killing Laravel for 3 days now.
At the moment, the following response is stored in the database:
[["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"]]
Answer::create([
'name' => $request->name,
'answer' => json_encode($answers), // Вот он
'a' => $answer_a,
'b' => $answer_b,
'c' => $answer_c,
]);
$name = Answer::select('name')->get();
$answers = json_decode(Answer::select('answer')->get()[0], true);
return view('home')->with(['name' => $name, 'answers' => $answers]);
<li>{{ $answers[3] }}</li>
Answer the question
In order to leave comments, you need to log in
https://laravel.ru/docs/v5/eloquent-mutators#%D0%B...
It is not required to perform json_encode and json_decode.
in this line
you get the model instance, not the answer field. Firstly, you need to get rid of json_decode, secondly, you will have the required field in $answers-
>
answer
use
return view('home', ['name' => $name, 'answers' => $answers]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question