0

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 = Input::get('social_class');
        $link = Input::get('link');
        foreach ($social_class as $socialClass) {
            $tsi = new TeamSocialIcon();
            $tsi->order_id = 0;
            $tsi->team_id = $insertedId;
            $tsi->social_class = $socialClass;
            $tsi->link = $link;
            $tsi->save();
        }
2
  • When are you using $sc? it seems to me you are trying to save the $social_class array, not the array element. Try, changing: $tsi->social_class = $social_class; to $tsi->social_class = $sc; Commented Oct 17, 2016 at 16:27
  • Hello I use $tsi->social_class = $socialClass; and updated some variable but tsi->link or $link still not catch value. and preg_replace error. Commented Oct 17, 2016 at 17:26

2 Answers 2

1

Try converting the array into string using explode method. You should also change the column data type to string or varchar for the data to be successfully saved. While retrieving the data you can convert the string back into array using implode method.

Sign up to request clarification or add additional context in comments.

Comments

0

I replied to myself for my solution

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

        for($i = 0; $i < count($social_class); $i++) {
            $tsi = new TeamSocialIcon();
            $tsi->order_id = 0;
            $tsi->team_id = $insertedId;
            $tsi->social_class = $social_class[$i];
            $tsi->link = $link[$i];
            $tsi->save();
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.