Skip to content

make value as both string or array acceptable in whereRelation #45030

Closed Answered by anilkumarthakur60
anilkumarthakur60 asked this question in Ideas
Discussion options

You must be logged in to vote

here is my solution

    public  function whereRelation($relation, $column, $operator = null, $value = null)
    {

        if (is_array($value)){
            return $this->whereHas($relation, function ($query) use ($column, $operator, $value) {
                if ($column instanceof Closure) {
                    $column($query);
                } else {
                    $query->whereIn($column, $value);
                }
            });
        }
        return $this->whereHas($relation, function ($query) use ($column, $operator, $value) {
            if ($column instanceof \Closure) {
                $column($query);
            } else {
                $query->where($column, $operat…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anilkumarthakur60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant