return $query->whereRaw('(`created_by` = :user_id or (`searchable` = 1 and (`share_to` is null or `share_to` RLIKE :email or `share_to` RLIKE :domain))) ', ['user_id' => $user->id, 'email' => "[[:<:]]$user->email[[:>:]]", 'domain' => '[[:<:]]' . strrchr($user->email, '@') . '[[:>:]]']);
$v_mysql_escaped = $mysqli->real_escape_string($v);
$mysqli->query("SELECT * FROM tblname WHERE columnname LIKE '$v_mysql_escaped'");
return $query->where(
function ($q0) use ($user) {
$q0->where('created_by', $user->id)
->orWhere(
function ($q1) use ($user) {
$q1->where('searchable', true)
->where(
function ($q2) use ($user) {
$q2->whereNull('share_to')
->orWhere('share_to', 'RLIKE', '[[:<:]]' . $user->email . '[[:>:]]')
->orWhere('share_to', 'RLIKE', '[[:<:]]' . strrchr($user->email, '@') . '[[:>:]]');
});
});
});
$sub_group_share_to = function ($q2) use ($user) {
$q2->whereNull('share_to')
->orWhere('share_to', 'RLIKE', '[[:<:]]' . $user->email . '[[:>:]]')
->orWhere('share_to', 'RLIKE', '[[:<:]]' . strrchr($user->email, '@') . '[[:>:]]');
};
$sub_group_serchable = function ($q1) use ($user) {
$q1->where('searchable', true)
->where($sub_group_share_to);
};
$sub_group = function ($q0) use ($user) {
$q0->where('created_by', $user->id)
->orWhere($sub_group_serchable);
}
return $query->where($sub_group);