Queries to get unpaid and unpaid invoices Here is my code:
add_hook('ClientAreaPageInvoices', 1, function($vars) {
    $user_id = $_SESSION[&quot;uid&quot;];
    $today = Carbon::now()-&gt;format('Y-m-d');
    $query_1 = Capsule::table('tblinvoices')
        -&gt;select(Capsule::raw('SUM(total) as total_aberto'))
        -&gt;where(array('userid' =&gt; $user_id, 'status' =&gt; 'Unpaid'))
        -&gt;get();
    $query_2 = Capsule::table('tblinvoices')
        -&gt;select(Capsule::raw('SUM(total) as total_vencido'))
        -&gt;where(array('userid' =&gt; $user_id, 'status' =&gt; 'Unpaid'))
        -&gt;whereDate('duedate', '&lt;=', $today)
        -&gt;get();
    $query_3 = Capsule::table('tblinvoices')
        -&gt;select(Capsule::raw('SUM(total) as total_pago'))
        -&gt;where(array('userid' =&gt; $user_id, 'status' =&gt; 'Paid'))
        -&gt;get();
    $array_1 = json_decode(json_encode($query_1), True); 
    $array_2 = json_decode(json_encode($query_2), True); 
    $array_3 = json_decode(json_encode($query_3), True); 
    $totalAberto = $array_1[0]['total_aberto'];
    $totalVencido = $array_2[0]['total_vencido'];
    $totalPago = $array_3[0]['total_pago'];
    return array ('totalAberto' =&gt; $totalAberto,
                  'totalVencido' =&gt; $totalVencido,
                  'totalPago' =&gt; $totalPago);
});

Is there any way to simplify the entire code in general?
It works well - I just want to learn other practices to make this type of consultation in a more optimized, and simplified way.
There seems to be a section in your code that you repeat three times. This can probably be placed in a separate function. Something like this:
function getInvoiceTotal($status, $onlyOverdue = FALSE)
{
    $query = Capsule::table('tblinvoices');
    $query-&gt;select(Capsule::raw('SUM(total) as total'))
          -&gt;where(['userid' =&gt; $_SESSION['uid'], 
                   'status' =&gt; $status]);
    if ($onlyOverdue &amp;&amp; ($status == 'Unpaid')) {
        $query-&gt;whereDate('duedate', '&lt;=', Carbon::now()-&gt;format('Y-m-d'));
    }    
    return $query-&gt;get()-&gt;total;        
}


add_hook('ClientAreaPageInvoices', 1, function($vars) {
    return ['totalAberto'  =&gt; getInvoiceTotal('Unpaid'), 
            'totalVencido' =&gt; getInvoiceTotal('Unpaid', TRUE), 
            'totalPago'    =&gt; getInvoiceTotal('Paid')];
});

Regretably I don't have Laravel installed so I cannot test this code, but I think the general idea is clear. Perhaps someone with more knowledge of Laravel can add to this answer?
Some notes:

I changed array(....) to [....].
I didn't understand the json_decode(json_encode()) bit. Perhaps to go from objects to arrays? I don't see what's wrong with using the actual objects. Here's where I have most doubt that my code is correct, since I haven't tested it.
I left out a lot of variables you used. Using variables, with good names, can make code easier to read, but in really good code, when a variable is only used once, it shouldn't be necessary.
I strongly advise you to write your code in English only. I had to find out what the meaning of 'Aberto', 'Vencido' and 'Pago' is. Not every programmer speaks Protuguese.