у меня три модели 1. Документ 2. Sharedoc 3. Пользователь
Document.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');
}
}
User.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» и «пользовательскими» таблицами… но я хочу, чтобы «document» объединялась с «sharedoc», а затем «sharedoc» соединялась с «user»…
как я могу это сделать?