title: Delete one of data JSON from Database
body: <p>I want to delete JSON from database but I can't</p>
  
  <p><a href="https://i.stack.imgur.com/7ae4K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ae4K.png" alt="enter image description here"></a></p>
  
  <p>My delete function in controller:</p>
  
  <pre><code>public function deletephoto($id)
      {
          $product = $this-&gt;productRepository-&gt;findWithoutFail($id);
          $photo = json_decode($product-&gt;photo_list,true);
          $photos = $photo[$id-1];
          unset($photos);
          $product-&gt;save();
  
          Flash::success('Photo deleted successfully.');
  
          return back();
      }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  Here my edit controller:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public function edit($id)
      {
          $product = $this-&gt;productRepository-&gt;findWithoutFail($id);
          $store = Store::pluck('name', 'id')-&gt;all();
          $photo = json_decode($product-&gt;photo_list);
          //dd($photo);
          
          $category = Category::pluck('name','id')-&gt;all();
          if (empty($product)) {
              Flash::error('Product not found');
  
              return redirect(route('products.index'));
          }
  
          return view('products.edit',compact('product','store','category','photo'));
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here my view blade.php. I'm using button to delete it.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@foreach($photo as $pro)
  &lt;div style="margin-right:10px" class="form-group col-sm-1"&gt;
       &lt;p&gt;&lt;img src="{{ env('FRONTEND_URL') . "/img/products/$product-&gt;id/$pro-&gt;name"}}"  width="100" height="100"/&gt;&lt;/p&gt;
       &lt;a href="{!! route('products.deletephoto', [$pro-&gt;id]) !!}" class='btn btn-default btn-xs' onclick="return confirm('Are you sure?')"&gt;Delete&lt;/a&gt;
  &lt;/div&gt;
  @endforeach</code></pre>
  </div>
  </div>
  </p>
  
  <p>I clik my button delete but it doesn't work.</p>
  
  <p><strong>LASTEST UPDATE</strong></p>
  
  <p>My Delete Function</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public function deletephoto($productid,$photoid)
      {
          $product = $this-&gt;productRepository-&gt;findWithoutFail($productid);
          $photo = json_decode($product-&gt;photo_list,true);
  
          foreach($photo as $key =&gt; $value) {
                  if($value['id'] == $photoid) { 
  
                  unset($photo[$key]);
  
                  }
          }
          
          
          return back();
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>my view blade.php</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@foreach($photo as $pro)
  &lt;div style="margin-right:10px" class="form-group col-sm-1"&gt;
       &lt;p&gt;&lt;img src="{{ env('FRONTEND_URL') . "/img/products/$product-&gt;id/$pro-&gt;name"}}"  width="100" height="100"/&gt;&lt;/p&gt;
       &lt;a href="{!! route('products.deletephoto', [$product-&gt;id,$pro-&gt;id]) !!}" class='btn btn-default btn-xs' onclick="return confirm('Are you sure?')"&gt;Delete&lt;/a&gt;
  &lt;/div&gt;
  @endforeach</code></pre>
  </div>
  </div>
  </p>
  
  <p>I use that code but it doesnt work too... </p>