【发布时间】:2016-12-19 03:24:07
【问题描述】:
我有两个模型之间的关系:Terminal 和 terminalRent。
一个终端可以有许多终端租金。 我想获得特定终端的最后一次租金。
$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
【问题讨论】:
-
你使用的是什么版本的 Laravel?
-
@Adrenaxus 我正在使用 5.2
标签: php laravel eloquent laravel-5.2