Php 新闻发布和用户关系与Laravel雄辩的ORM
我正在尝试与我的users表和news_posts表建立关系。当我查看运行的查询时,它显示了以下内容Php 新闻发布和用户关系与Laravel雄辩的ORM,php,laravel,eloquent,Php,Laravel,Eloquent,我正在尝试与我的users表和news_posts表建立关系。当我查看运行的查询时,它显示了以下内容 select * from `news_posts` where `news_posts`.`deleted_at` is null and `id` = '1' limit 1 select * from `users` where `users`.`deleted_at` is null and `users`.`id` is null limit 1 所以我想弄明白为什么user.id会
select * from `news_posts` where `news_posts`.`deleted_at` is null and `id` = '1' limit 1
select * from `users` where `users`.`deleted_at` is null and `users`.`id` is null limit 1
所以我想弄明白为什么user.id会显示NULL
我正在尝试访问$news\u post->author->first\u name和$news\u post->author->first\u name
试试这个
foreach (NewsPost::all() as $news_post)
{
echo $news_post->author->name;
}
运行这些查询所需的代码在哪里?
foreach (NewsPost::all() as $news_post)
{
echo $news_post->author->name;
}