
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();
Answers 1
-
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();
2Replace 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.
Random Code Snippet Queries: Laravel
- How to restore deleted records in laravel
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- How to call controller function from view in Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- In order to use the Auth::routes() method, please install the laravel/ui package
- How to run a specific seeder class in laravel
- Laravel create table migration with model
- How to create controller in laravel
- How to get images from AWS s3 and display in Laravel blade
- How to make Copy or Duplicate table row in laravel
- Update existing pivot table data in laravel
- How to send email in laravel
- How to add class to tr in table using foreach in laravel
- How to check data inserted or deleted in pivot after toggle method
- How to print form data in laravel
- Define variable and use in Laravel controller method
- Print query in laravel
- How to insert value to additional columns in pivot table in laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- How to restore multiple records after soft-deletes in Laravel
- How to get last month records in Laravel
- How to use bootstrap pagination in laravel 8
- How to Access Array in blade laravel
- How to prevent host header attack in Laravel
- How to get query string value in laravel