Call to a member function getRelationExistenceQuery() on array in Laravel

Updated at 06-Jul-2022, By samarjeet kumar

Call to a member function getRelationExistenceQuery() on array in Laravel

Through many examples, we will learn how to resolve the "Call to a member function getRelationExistenceQuery() on array in Laravel".

The below code giving this error Call to a member function getRelationExistenceQuery() on array.
$users = User::whereHas(['posts' => function($q){
    $q->where('created_at', '>=', '2015-01-01 00:00:00');
}])->get();
  • WhereHas() method to get the users record those have at least one post

    $users = User::whereHas('posts', function($q){
        $q->where('created_at', '>=', '2022-01-01 00:00:00');
    })->get();
    

    Replace code with above code snippets. It will help you to find the solution for your query. Because whereHas method does not accept an array. It will return the users records that has at least one post with additional query constraints.

Back to code snippet queries related laravel