Skip to content

Commit

Permalink
refactor: update eloquent repo for category
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisdom Ebong authored and tuxpiper committed Dec 4, 2023
1 parent 12ab730 commit e047b57
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ private function setSearchCondition(Builder $builder, ?SearchData $search_fields

$is_admin = $search_fields->getFilter('is_admin');
if ($is_admin === false) {
$builder->where(function (Builder $builder) use ($search_fields) {
$builder->where(function (Builder $builder) {
// Default always get categories with null roles or has everyone
$builder->whereNull('role');

// This query isn't working as expected
$builder->orWhere('role', 'like', '%everyone%');

$role = $search_fields->getFilter('role');
if (isset($role) && !is_null($role)) {
$builder->orWhere('role', 'like', "%" . $role . "%");
}

// If it's a logged in user
$user_id = $search_fields->getFilter('user_id');
if (isset($user_id) && !is_null($user_id)) {
// Where the user is the owner of the category
$builder->orWhere(function (Builder $query) use ($user_id) {
//TODO: Fix this query in future release
$query->where('role', 'like', '%me%')
->where('user_id', $user_id);
});
}
$builder->orWhere('role', 'LIKE', "%everyone%");
});

$user_id = $search_fields->getFilter('user_id');
if (isset($user_id) && !is_null($user_id)) {
// Where the user is the owner of the category
$builder->orWhere(function (Builder $query) use ($user_id) {
$query->where('role', 'LIKE', "%me%")
->where('user_id', $user_id);
});
}

$role = $search_fields->getFilter('role');
if (isset($role) && !is_null($role)) {
$builder->orWhere(function (Builder $query) use ($role) {
$query->where('role', 'LIKE', "%" . $role . "%");
});
}
}

return $builder;
Expand Down

0 comments on commit e047b57

Please sign in to comment.