4 years ago

[Help] Need to add image and text inside a Json DB column

Posted 4 years ago by lucassimines

Hello guys, I making some kind of Repeater Field.

I have a DB column named Images, this column actually has some Json image filenames, like:

{"img": ["image1.jpg"],"img":["image2.jpg"]}

Now I'm trying to add a text field (description) to each image inside this column, here are my functions in my Controller, but still no success..

public function update($id, ProjectRequest $request)
        $this_project = $this->project->find($id);
        if ($request->file('images')) {
            $filename = "";
            foreach ($request->images as $key => $img) {
                $file = $img['img'];
                if (empty($file)) {
                    $file_num = $request->uploaded_img[$key];
                    $uploadedFile = $this_project->images['img'][$file_num];
                    $filename .= ',' . $uploadedFile;
                } else {
                    $original_file = $file->getClientOriginalName();
                    $destinationPath = public_path('/images/uploads/');
                    $filename .= ',' . Helpers::safeFilename($original_file);
                    $single_file = Helpers::safeFilename($original_file);
                    $file->move($destinationPath, $single_file);
            $files = trim($filename, ',');
            $files_array = explode(',', $files);

                'images' => [
                    'img' => $files_array



I'm trying to add the requested image filenames using merge, but if I do that, my text field disappears from the array..

How can I request all values including my images filename and description? Thanks!

Please sign in or create an account to participate in this conversation.