2

I need to display the JSON data which is inside the column extras_name individually inside a input boxes with the value filled on edit

enter image description here

Here's the blade file codes

<div class="card">
        <h5 class="card-header">
            Manage Extras
        </h5>
        <div class="card-body">
            {{ $customProduct }}
            <br><br><br>

            <div class="optionBox">
                <div class="block main">
                    <div class="form-row pb-2">
                        <div class="col">
                          <input type="text" class="form-control" name="extras_name[]" value="{{ $customProduct->name }}" placeholder="Name">
                        </div>
                        <div class="col">
                          <input type="text" class="form-control" name="extras_price[]" placeholder="Price">
                        </div>
                        <div class="col">
                            <button type="button" class="remove btn btn-danger"><i class="fas fa-trash-alt"></i></button>
                        </div>
                    </div>
                    <div class="block mt-2 ">
                        <button type="button" class="add btn btn-success">Add Extras</i></button>
                    </div>
                </div>
            </div>
        </div>
    </div>

Here's the Controller Edit function

public function edit($venue, CustomProduct $customProduct)
    {     
        $data = [     
            'customProduct'=>$customProduct,
        ];

        return view('manage.custom-products.edit')->with($data);
    }

Here's how the data is saved in the database

enter image description here

3 Answers 3

1

If you want to show data in a table then you can use this code

<td>

 @foreach(json_decode($value->extras_name, true) as $extras_name)

     {{ $extras_name}}

   @endforeach
</td>
Sign up to request clarification or add additional context in comments.

Comments

0

first of all json_decode this
and then in foreach you can use that.
Blade File:

@if(!empty(json_decode($data->extras_name))) {{--JUST FOR CHEKING THAT IF THIS WAS NOT JSON OR THIS WAS NULL, THE ERROR NOT SHOWING--}}
    @foreach(json_decode($data->extras_name as $title=>$value))
        <label>
            {{$title ?? ''}} : {{$value ?? ''}}
        </label>
        <br/>
    @endforeach
@endif

Comments

0

it doesnt make sense to do that instead you can show your values on list item below your input and when new value is added or removed refresh the list using ajax

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.