0
<label class=" ORGAD1-labeltext2">Color</label>
<select class="select-color-multiple  col-sm-12 ORGAD16-color"  multiple="multiple" name="color[]" id="color">
    <option value="">choose color</option>
    <option value="1" >Black</option>
    <option value="2">White</option>
    <option value="3">Green</option>
    <option value="4">Red</option>
    <option value="5">Blue</option>
</select>

In dropdown I select multiple values eg:2 (white) 4(red) 5(blue) passes to controller

$rules['color' => 'required']
$colors = $Request->color;
$choosecolors = implode(',', $colors);

[ dd(colors) if made dd means its shows "1,2,3"]

$store = modelcolor::insertcolors($choose)

In my model model color

public static function  insertcolors($choose)
{
    $createColor = new Colorstable;
    $createColor->colorslist = $choose;
}

If store this value means its shows following error:

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'colorslist' at row 1

here colorlist column is in int(11)

1
  • 1
    As you crate a string of values, then the column's type should be a varchar instead of an int. Int's cannot store commas or spaces, so it very likely that the example is only saving 1 because the data is truncated at the first comma for not being a number. Commented Jan 10, 2022 at 14:40

1 Answer 1

1

You do string with your implode, so you have to change your column int to varchar

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

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.