We want's to need those complain, which lifetime(created\_at - now()) is grater then a complain lifetime(the lifetime amount stored on complain\_type table) by eloquent relationship.

**01.complain table:**

```
+---+------------+-----------------+
|id | complain_preset_id  | created_at      |
+---+------------+-----------------+
| 1 | 48         | 3/16/2018 10:30 |
| 2 | 13         | 3/16/2018 10:43 |
| 3 | 12         | 3/16/2018 10:57 |
+---+------------+-----------------+

```

**02. Complain Preset Table:**

```
+---+------------+-----------------+
|id | type_id    | created_at      |
+---+------------+-----------------+
| 1 |  1         |  3/16/2018 6:29 |
| 2 |  2         |  3/16/2018 6:29 |
| 3 |  3         |  3/16/2018 6:29 |
+---+------------+-----------------+

```

**03. complain type table**

```
+---+------------+
|id | lifetime   |
+---+------------+
| 1 |  10        |
| 2 |  36        |
| 3 |  360       |
| 4 |  500       |
+---+------------+

```

> 
> the relation between complain->preset is:
> 
> 
> 

```
public function preset()
{
    return $this->belongsTo(ComplainPreset::class, 'complain_preset_id');
}

```

> 
> the relation between preset->complain is:
> 
> 
> 

```
public function complains()
{
    return $this->hasMany(Complain::class, 'complain_id');
}

```

> 
> AND preset->complain\_type:
> 
> 
> 

```
public function complainType()
{
    return $this->belongsTo(ComplainType::class, 'type_id');
}

```

> 
> complain\_type->preset:
> 
> 
> 

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

```

Their is no direct relationship between complain to complain\_type.

Here is our solution eloquent query. but that query doesn't work.

**The relation is complain->preset->complain\_type**

```
Complain::with(['preset' => function ($q) {
    $q->with(['complainType' => function($q2) {
        $q2->whereRaw('SUBTIME(NOW(), lifetime) > complains.created_at');
    }]);
}])->whereDate('created_at', '=' , Carbon::today());

```

In line 3, this query didn't get complains.created\_at, because this line refer to complain\_type table. 
On line 3 we need to access complains.created\_at.

**Is their any eloquent way ?**