you can try this https://laravel.com/docs/5.5/queries#json-where-clauses
Jan 25, 2018
6
Level 1
Working with Postgres JSONB in Laravel 5.5
Here's our table schema
Schema::create('contacts', function(Blueprint $table)
{
$table->uuid('id')->default(\DB::raw('gen_random_uuid()'))->comment('primary key');
$table->string('email', 100)->nullable()->comment('email address');
$table->jsonb('data')->nullable()->comment('Any params go here');
$table->timestamps();
});
Here's an insert statement in Tinker
Contact::create(['email'=>'[email protected]', 'data'=>'{"first_name":"Geoff","info":{"id":1234123,"groups":[101,202,303]}}'])
Here's a sample query
Contact::where('data->first_name', 'Geoff')->first()
App\Models\Contact {#890
id: "8eeab075-57ae-4b29-8aca-df8f7c296dd4",
email: "[email protected]",
data: "{"first_name": "Geoff", "info": {"id": 1234123, "groups": [101, 202, 303]}}",
created_at: "2018-01-25 18:04:03",
updated_at: "2018-01-25 18:04:03",
}
So far so good.
How do I find contacts that belong to group 202?
Please or to participate in this conversation.