Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

smacy's avatar
Level 1

whereRelation query

how to query value as a type of array for query whereRelation eloquent relation

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php
  public function whereRelation($relation, $column, $operator = null, $value = null)
    {


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

I want to query with value as a type of array

\App\Models\User::whereRelation('roles','name',null,['admin','editor'])->get()

how can I achieve this

0 likes
2 replies
smacy's avatar
Level 1

i can achieve this with which i don't want

whereHas('roles',function($q)use($array){
$q->whereIn('name',$array);
})
Lumethys's avatar

your question is not clear, what exactly do you want to achieve?

Please or to participate in this conversation.