关于模型关联 获取不到关联信息 求教
class Comment extends Model
{
/**
* 获取此评论所属文章
*/
public function post()
{
return $this->belongsTo('App\Post');
}
}
按文档这样操作后,却获取不到文章信息
php artisan tinker
App\Comment::find(1)->post()->title
// 返回了 null
App\Comment::find(1)->post()->first()->title
// 这样才返回了标题
为什么会这样,是我哪里写错了吗?求教
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: