Array of values to be saved by multiple selection of checkbox


This Content is from Stack Overflow. Question asked by go_live

There is a system developed with Laravel, and I would like to store multiple selected data in the conditions column using the implode function.
Currently, it is saved as shown in the image below.
I want to save data in a form like “1,2,3,4” using the implode function.
How can I achieve what I want?

In shops Table


    public function store(Request $request)
        $param = $request->except([

        if ($request->filled('logo_cache')) {
            $param['logo'] = $request['logo_cache'];
        } else {
            if (!$validator->errors()->has('logo') && $request->has('logo')) {
                $path = $request['logo']->store('public/'.config('constants.UPLOAD_IMG_SHOP'));
                $filename = basename($path);
                $param['logo'] = $filename;
                $request['logo_cache'] = $filename;
            } else {
                $param['logo'] = null;

        for ($i = 1; $i <= config('constants.SHOP_IMAGES_MAX'); $i++) {
            if ($request->filled('image_cache'.$i)) {
                $param['image'.$i] = $request['image_cache'.$i];
            } else {
                if (!$validator->errors()->has('image'.$i) && $request->has('image'.$i)) {
                    $path = $request['image'.$i]->store('public/'.config('constants.UPLOAD_IMG_SHOP'));
                    $filename = basename($path);
                    $param['image'.$i] = $filename;
                    $request['image_cache'.$i] = $filename;
                } else {
                    $param['image'.$i] = null;

        //Add code
        if ($request->filled('conditions')) {
            $param['conditions'] = implode(",", $request['conditions']);

        if ($validator->fails()) {
            return redirect('/shop/create')

        $param['area_id'] = Auth::user()->area_id;


        session()->flash('alert_message', config('constants.ALERT.SUCCESS_CREATE'));
        session()->flash('alert_style', 'success');

        return redirect()->route('');


                        <div class="c-form__check c-form__check_inline">
                            @foreach(config('constants.FORM.SHOP_CONDITIONS') as $key => $value)
                            <label><input type="checkbox" name="conditions[]" value="{{ $key }}" {{ old('conditions', $shop->conditions) == $key ? 'checked' : '' }}> {{ $value }}</label>


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?