0

我有三个模型 1.Document 2.Sharedoc 3.User

文档.php

class Document extends Model
{
    public function sharedoc(){

        return $this->hasMany('App\Sharedoc','docId','id'); 

    }

    public function user(){

        return $this->belongsTo('App\User','userId','id');
    }
}

Sharedoc.php

class Sharedoc extends Model
{
    public function document(){

        return $this->belongsTo('App\Document','docId','id'); 

    }
}

用户.php

class User extends Authenticatable
{
public function document(){

        return $this->hasMany('App\Document','userId','id'); 

    }
}

控制器:

$data = Document::with('sharedoc','user')
           ->where('userid',Auth::user()->id)
           ->orderBy('id','DESC')
           ->get();
return $data;

结果是:

10  
    id  21
    name:   " 20190121083621.txt"
    userId: 3
    type:   "txt"
    size:   0
    created_at: "2019-01-21 08:36:21"
    updated_at: "2019-01-21 08:36:21"
    sharedoc:   
         0: 
             id:    9
             docId: 21
             fromUserId:    3
             toUserId:  6
             created_at:    "2019-01-22 15:34:50"
             updated_at:    "2019-01-22 15:34:50"
        1   
             id:    8
             docId: 21
             fromUserId:    3
             toUserId:  5
             created_at:    "2019-01-21 09:32:39"
             updated_at:    "2019-01-21 09:32:39"
    user:   
        id: 3
        name:   "تست تست"
        email:  "f.ghorbani@gmail.com"
        active: 1
        isClickActiveLink:  1
        isSendMail: 1
        isAdmin:    1
        created_at: "2019-01-20 15:53:29"
        updated_at: "2019-01-20 16:37:32"

在这个结果中,'document' 表加入了 'sharedoc' 和 'user' 表......但我希望 'document' 加入 'sharedoc',然后 'sharedoc' 加入 'user'...... 我该怎么做呢?

4

0 回答 0