如何从数据透视表获取每个表列的所有数据?

时间:2019-09-24 19:44:46

标签: laravel relationship

我在任务模型中具有以下关系:

public function taskUser() {
    return $this->belongsToMany('App\User', "task_user", 'task_id','user_receive_id')->using('App\TaskUser')
        ->withPivot('user_assigned_id');
}

当我在控制器中使用类似$task->taskUser->pivot之类的东西时,我收到以下数据:

        'data': [
    task_id : 1,
    user_receiver_id: 1,
    user_assign_id: 2,
    ]

我想收到的是这样的东西:

    'data' : [
          task: {
                   all information from task model by id
                       }
          user_assign_id: {
                   all information from task model by id
                       }
          user_receiver_id: {
                   all information from task model by id
                       }
]

0 个答案:

没有答案