Laravel 5.2 Elequent ORM save()不起作用

时间:2016-08-15 15:34:00

标签: php laravel orm

我在帖子表上有一个名为 hotness 的列,我正在尝试使用elequent orm save()方法更新它

这是我的代码:

$rank = new Ranking;
$post = Post::where('id', $post_id)
    ->select(DB::raw("(select count(*) from votes where votes.vote = '1' and votes.post_id = posts.id) as upvotes, (select count(*) from votes where votes.vote = '0' and votes.post_id = posts.id) as downvotes, posts.created_at, posts.hotness"))
    ->first();

echo "Starting HOTNESS: " . $post->hotness; //CORRECT VALUE

$post->hotness = $rank->hotness($post->upvotes, $post->downvotes, strtotime($post->created_at));

echo "Updated HOTNESS: " . $post->hotness; //CORRECT VALUE

$post->save();

运行此命令并检查我的数据库后,帖子的热度仍然是起始值。两个echo都打印出正确的值,并且没有错误被抛出。知道为什么不更新吗?

0 个答案:

没有答案