Level 51
You can use whereJsonContains
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to filter child records with conditions if an element is present like in_array(someElement, json_decode(database_column)) but don't know exactly what will be the syntax. I have done it through loops but I want to clear that loops and wrap it up in one query.
Till now I have done the following,
$projects = Project::with([
'tasks' => function($query) use ($request) {
$query->when($request->input('region_id') !== 'All', function ($query) use ($request) {
$query->where('region_id', $request->input('region_id'));
})->when($request->input('taskowner_id') !== 'All', function ($query) {
});
}
])->get(['id', 'project_name', 'customer_id']);
i want to insert the following line to that when the condition of task_owner_id
if (in_array($taskOwnerName->emp_name, json_decode($task->task_owner, false), true)) {
}
You can use whereJsonContains
Please or to participate in this conversation.