Laravel offers helpers to query JSON columns for databases that support them.
Currently, MySQL 5.7+, PostgreSQL, SQL Server 2016, and SQLite 3.9.0 (using the JSON1 extension)
1// To query a json column you can use the -> operator 2$users = User::query() 3 ->where('preferences->dining->meal', 'salad') 4 ->get(); 5// You can check if a JSON array contains a set of values 6$users = User::query() 7 ->whereJsonContains('options->languages', [ 8 'en', 'de' 9 ])10 ->get();11// You can also query by the length a JSON array12$users = User::query()13 ->whereJsonLength('options->languages', '>', 1)14 ->get();
Tip given by @cosmeescobedo