我有表:operations
,remarks
和adjustments
。
operations
:
| id | user_id | operation | start_date | end_date |
| 1 | 2 | opeartion1 | 1/1/16 | 5/5/16 |
| 2 | 2 | opeartion2 | 1/1/16 | 5/5/16 |
remarks
:
| id | user_id | operation_id | remarks |
| 10 | 4 | 1 | remarks1 new |
| 13 | 4 | 2 | remarks22new |
adjustments
:
| id | remarks_id | user_id | before | after | created_at | updated_at |
|:--:|:----------:|:-------:|:----------------------:|:----------------------------:|:-------------------:|:-------------------:|
| 1 | 10 | 6 | {"remarks":"remarks1"} | | {"remarks":"remarks1 new"} | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 2 | 13 | 7 | {"remarks":"remarks1"} | | {"remarks":"remarks1 new"} | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
我想在adjustments
控制器的operation_id
方法中从Operation
表中获取特定show()
的数据:
$history = Adjustment::with('user','remark')->get();
从这里我得到adjustments
表中的所有行,如下所示:
Jerry Nienow 2016-05-12 07:00:24 {"remarks":"remarks1"} {"remarks":"remarks1 new"}
Jerry Nienow 2016-05-12 07:01:09 {"remarks":"remarks22"} {"remarks":"remarks22new"}
但我想要一个特定的operation_id
这样:
Jerry Nienow 2016-05-12 07:00:24 {"remarks":"remarks1"} {"remarks":"remarks1 new"}
答案 0 :(得分:1)
只需加入remarks
表,然后使用此$operationId
Adjustment::join('remarks', 'remarks.id','=', 'adjusments.remarks_id')->where('remarks.operation_id', '=', $operationId)->get();
您应首先设置$operationId
。