Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sama's avatar
Level 1

Insert multiple line in table laravel

I want to insert three lines in the same field option of my QuestionOption table with the same id of the table quesion the problem is that it just inserts me one line I use Laravel 5.4

    $question_option = new QuestionOption;

        $question_option->option = $request->option_one;
        $question_option->option = $request->option_two;
        $question_option->option = $request->option_three;
        $question_option->correcte = $request->option_correcte;
        $question_option->question_id = $question->id;

        $question_option->save();
0 likes
1 reply
jlrdw's avatar
$combined3 = $request->option_one . '|' . $request->option_two . '|' . $request->option_three;

I used a pipe for delimiter only as example.

You can pick your delimiter, or store as small json object. Choice is yours.

Now me I'd do a bit different.

I'd set up a one to many relation and store in a separate table.

https://laravel.com/docs/5.6/eloquent-relationships#one-to-many

Please or to participate in this conversation.