Question: I have default laravel `users` table and my custom `educations` table in my database. In `educations` table users can save education histories. 

Example `educations` data:

```
------------------------------------------------------------
id | user_id | university | speciality | finish_year | level
------------------------------------------------------------
 1 |   16    |   Boston   |  Developer |    2018     |   4 
------------------------------------------------------------
 2 |   10    |   Sinergy  |   Designer |    2014     |   4 
------------------------------------------------------------
 9 |   16    |   Sinergy  |  Economist |    2010     |   8 
------------------------------------------------------------

```

Now how I can get users using laravel eloquent by education level?

For example get users where education level == 4

Answer: 
Considering that you have a `educations` method in your User model that represents a `HasMany` association, you can use eloquent's `has` (or `whereHas`) method:

```
$users = App\User::whereHas('educations', function ($query) {
    $query->where('level', 4);
})->get();

```

Here's a link to the [docs](https://laravel.com/docs/5.7/eloquent-relationships#querying-relationship-existence).
If you have the relationship setup correctly, so in your `User` model you should have something like this:

```
public function educations() {
    return $this->hasMany(Education::class);
}

```

Then a simple use will be the following:

```
User::with(['educations' => function($query) {
    $query->where('level', 4);
}])->get()->filter(function($user) {
    return $user->educations->count() > 0;
});

```

The opposite approach would be:

```
Education::with('user')->where('level', 4)->get();

```

This will give you list of educations where the level is 4, and for each the user assigned to it.