I want to remove JSON object value from mysql database via eloquent. I have tried with this code it works but I have to pass array key "$.language[1]".
Here is JSON object {"name":"The Lord of the Rings:The Fellowship of the Ring","language":["Hindi","English","Spanish"]} stored in database.
Here I want to remove English language from all the records.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Book;
use DB;
class BookController extends Controller
{
public function store(){
$book = new Book;
$book->attributes = $jsonAttr;
$book->save();
echo "Book saved";
die;
}
public function updateLanguage()
{
$result = Book::where('attributes->language','LIKE','%English%')->update(['attributes' => DB::raw('JSON_REMOVE(attributes, "$.language[1]")')]);
//$result = Book::where('attributes->language','LIKE','%H%')->get();
echo "<pre>";
print_r($result);
die;
}
}
Any help would be appreciated.