$q = Tags::where('name', 'LIKE', '%' . $like . '%')
->whereNotIn('id', $deprecate)
->where(function ($q) use ($id) {
$q->whereHas('closure', function ($q) use ($id) {
$q->where('tags_closure.ancestor_id', '=', $id);
})->orWhere(function ($q) {
$q->where('is_sealed', 1);
});
})
->with('closure');
$sql = $q->toSql();
var_dump($sql);