0

I am trying to display some information from data that I put into a table. But the result is as it is, only the information of the first record is being displayed despite the efforts made to display the information of the latest record added into that table.

I'll appreciate your help...

HERE IS THE CODE INSIDE MY BLADE PAGE

@if(!empty(Auth::user()->credo->money[0]->orderBy('updated_at','ASC')->get('is_payed')) == 1 )
    <h4>You are eligible. <br>BMFA thanks you for the corcern.<hr/><span style="font-size:12px"> 
You refund is {{ Auth::user()->credo->money[0]->amount }}$</span>
    </h4>
@endif

MY CONTROLLER

    public function index()
    {
        $Users = User::all();
        $Credos = Credos::all();
        $MoneyP = MoneyP::all();
        $context = [
            'Credos' => $Credos,
            'MoneyP' => $MoneyP,
            'Users' => $Users,
        ];

        return view('/')->with($context);
    }
BMFA
  • 11
  • 5
  • 1
    If you need the most recent row (with greatest datetime) then you must use `DESC` sorting. – Akina Dec 27 '21 at 11:37

1 Answers1

0
$results = Auth::user()->credo->money[0]->orderBy('updated_at','ASC')->get();
    @foreach ($results as $result)
        @if($result->is_payed == 1)
            <h4>You are eligible. <br>BMFA thanks you for the corcern.<hr/><span style="font-size:12px">
            You refund is {{ Auth::user()->credo->money[0]->amount }}$</span>
            </h4>
        @endif
    @endforeach