lundi 17 octobre 2016

How to Store Array Data Using Laravel foreach with ORM

create_team_social_icons_table.php

        $table->increments('id');
        $table->integer('order_id');
        $table->integer('team_id');
        $table->integer('social_class');
        $table->string('link');

Hello, I have two different array from create form social_class[] and link[]. Trying to record values from a form using the form at one time.

<select name="social_class[]">
<select name="social_class[]">
<select name="social_class[]">
<select name="link[]">
<select name="link[]">
<select name="link[]">

I received an error message:

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array.

        $social_class = $request->social_class;
        $link = $request->link;

        foreach ($social_class as $sc) {
            $tsi = new TeamSocialIcon();
            $tsi->order_id = 0;
            $tsi->team_id = $insertedId;
            $tsi->social_class = $social_class;
            $tsi->link = $link;
            $tsi->save();
        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire