I can't think of a good title I'm so sorry but I need help.
I have a field that is added by jquery depending on how many questions are present in the database, so for example I have 3 questions in the db i will have 3 answer fields too, it will look like this:
answer_1 answer_2 answer_3
since i am not sure how many questions there can be, i need to loop the $request->answer_1, 2 and 3 in the controller to store the answers. but i'm not sure how to do it. I have tried:
for($i = 0; $i < total.count.of.answers; i++){
$x = $i + 1;
$answer = new Answer;
$answer->answer = $request->answer_{$x};
$answer->save();
}
but not working. How do I achieve this?
(note i can already send the answers to the backend using jquery, problem is only how i can pull it in the controller)
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2PtMAOL
via IFTTT
Aucun commentaire:
Enregistrer un commentaire