search

Home  >  Q&A  >  body text

tp5.1 model association new updates

$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();

Two tables are related. I want to update a piece of data in the main table, and I need to add a new piece of data in the related table. How can I use the related model to achieve this in one step? I can't implement the above code, please give me some advice. . .

文1968 days ago1515

reply all(1)I'll reply

  • 秋香姐家的小书童

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

    Do it in two steps, 1. Update data 2. Add new

    reply
    0
  • Cancelreply