【发布时间】:2015-03-10 16:08:21
【问题描述】:
我们有两张桌子
标题
+------+--------------------------------------+--------------+---------------------+
| id | title | subs_updated | created_at |
+------+--------------------------------------+--------------+---------------------+
| 104 | movie 1 | | 2014-11-11 12:08:28 |
| 129 | movie 2 | | 2014-11-11 12:08:29 |
+------+--------------------------------------+--------------+---------------------+
订阅
+----+----------+----------+---------+---------------------+
| id | label | title_id | subs | created_at |
+----+----------+----------+---------+---------------------+
| 13 | English | 104 | English | 2014-11-12 05:05:39 |
| 15 | Italian | 104 | Italian | 2014-11-12 05:25:00 |
| 16 | Dutch | 104 | Dutch | 2014-11-13 05:40:51 |
| 18 | Arabic | 129 | Arabic | 2014-11-12 06:05:28 |
| 19 | Arabic | 129 | Arabic | 2014-11-12 06:07:23 |
+----+----------+----------+---------+---------------------+
在 SubsController 我有:
public function attach()
{
$input = Input::except('_token');
if ( ! Input::get('label') || ! Input::get('subs')) {
return Response::json(trans('subs::main.fillAllRequiredFields'), 400);
}
if ( ! isset($input['title_id']))
{
return Response::json(trans('dash.somethingWrong'), 500);
}
else
{
$this->model->fill($input)->save();
}
return Response::json($this->model, 201);
}
子模型
<?php
class Link extends Entity {
public $table = 'subs';
protected $guarded = array('id');
public function title()
{
return $this->belongsTo('Title');
}
}
- 我想为 subs 表中的标题 (title_id) 按创建日期 (created_at) 查找最新的 sub。
- 将该结果(日期)插入到标题表 => 标题 (id) => subs_updated
- 将该查询与上述 attach() 函数一起使用
非常感谢任何帮助
【问题讨论】:
-
能否将您的
Sub和Title模型的代码添加到问题中? -
嗨 Lucas,我已经发布了潜艇模型。标题模型太大,无法发布。
标签: laravel laravel-4 eloquent