【问题标题】:How to retrieve data from a recent record inserted into a database table? [duplicate]如何从插入数据库表的最近记录中检索数据? [复制]
【发布时间】:2022-01-26 09:09:18
【问题描述】:

我正在尝试从我放入表格的数据中显示一些信息。但结果是这样,尽管努力显示添加到该表中的最新记录的信息,但只显示第一条记录的信息。

感谢您的帮助...

这是我刀片页面中的代码

@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

我的控制器

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

        return view('/')->with($context);
    }

【问题讨论】:

  • 如果您需要最近的行(日期时间最长),那么您必须使用DESC 排序。

标签: php laravel if-statement


【解决方案1】:
$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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多