终端可以有许多终端租赁.
我想获得特定终端的最后租金.
$lastRent = Terminal::with('terminalRent')->where('id', $id)->orderBy('id', 'desc')->first();
当使用where()时,它将反映Modal上的那些我希望获得与特定终端相关的terminalRent的最后一条记录. $id是终端的Id,表连接如下:
Terminal
----
ID
terminalRent
-----
ID
terminal_id <--- this is the foreign key for the ID of the Terminal Table
解决方法:
如果终端和终端租金之间的关系很多,你可以这样做:
$lastRented = $lastRent->terminalRent->last();
确保你最后通过dd($lastRented)租借;
让我知道你是怎么办的
编辑:如果这给你不正确的terminalRent实例,请尝试first();我不记得Eloquent默认如何命令eagerlaoded关系.