我有三个模型1.Document 2.Sharedoc 3.User
Document.php
DispatchSemaphore
Sharedoc.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');
}
}
User.php
class Sharedoc extends Model
{
public function document(){
return $this->belongsTo('App\Document','docId','id');
}
}
控制器:
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;
在此结果中,“文档”表与“ sharedoc”和“用户”表结合在一起…但是我希望“文档”与“ sharedoc”结合,然后“ sharedoc”与“用户”结合… 我该怎么办?