I have a **customers table** and a **customer transactions** table.

This is the customers' table below.

[![enter image description here](https://i.stack.imgur.com/wSqDn.png)](https://i.stack.imgur.com/wSqDn.png)

This is the customer transactions table below.

[![enter image description here](https://i.stack.imgur.com/l9yzZ.png)](https://i.stack.imgur.com/l9yzZ.png)

This is what I want to achieve below:

[![enter image description here](https://i.stack.imgur.com/mouTt.png)](https://i.stack.imgur.com/mouTt.png)

I want to be able to sum up the amount column such that the result is grouped by customers and month and year.

This is what I've done so far:

I created a model for both **Customers** and **Customers transactions**. I have this relationship in the Customer transactions model:

```
    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

```

I also have a Customer controller where I have the logic to fetch the data. In my CustomerController file:

```
    public function index()
    {
        $transactions = CustomerTransaction::with('customer')->get();

        dd($transactions);
    }

```