PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 2, 2022

[FIXED] How to retrieve data from a recent record inserted into a database table?

 January 02, 2022     if-statement, laravel, php     No comments   

Issue

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);
    }


Solution

$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


Answered By - mohammad gitipasand
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing