登录

tp5.1 模型关联新增更新

$user = \app\index\model\User::find($uid);
         $user->totalpoint = $details['integral'] + $user['totalpoint'];
         $user->comment->uid = $uid;
         $user->comment->type = 4;
         $user->comment->bid = $id;
         $user->comment->content = '观看文章获取';
         $user->comment->num = $details['integral'];
         $user->together('comments')->save();

两张表关联,主表我要更新一条数据,关联表我需要新增一条数据,怎么用关联模型一步到位实现? 面代码我尝试实现不了,求大神指点。。。

# PHP
文 1759 天前 1380 次浏览

全部回复(1) 我要回复

  • 秋香姐家的小书童

    秋香姐家的小书童2019-06-25 14:47:33

    分两步做,1.更新数据     2.新增 

    回复
    0
  • 取消 回复 发送