🎃
Я изменил модель и вью, как теперь провести миграцию, чтобы обновилась таблица в бд и запросы к ней в модели
Size: a a a
🎃
w
🎃
R
w
R
СП
СП
w
w
w
R
w
R
w
🎃
🎃
T
txt CommentRes:
public function toArray($request)
{
return ['user' =>
new UserRes($this->loadMissing('user'))
];
}
UserRes:
public function toArray($request)
{
return ['posts' =>
PostRes::collection($this->whenLoaded('posts')),
];
}
PostRes:
public function toArray($request)
{
return ['user' =>
new UserRes($this->whenLoaded('user'))
];
}
Comment::resolveRelationUsing(
'user', function ($cM) {
return $cM->belongsTo(
App\User::class, 'user_id','id');
});
App\User::resolveRelationUsing('posts', function ($uM) {
return $uM->hasMany(Posts::class, 'user_id','id');
});
$com=Comment::with(['user.posts'])->find(1);
// показывает связь posts
// dd($com->toArray());
return new CommentRes($com);
// не показывает связь posts
ЕП
T