我正在尝试向我的 laravel 应用程序添加评论系统。但我似乎无法让它工作。我有两个模型
class Post extends \Eloquent {
protected $table = 'posts';
public function comments()
{
return $this->hasMany('Comment','postId');
}
}
和我的评论模型
class Comment extends \Eloquent {
protected $table = 'comments';
public function post()
{
return $this->belongsTo('Post');
}
}
在我的仪表板控制器中,我试图从模型中获取输出
use App\Models\Post;
use App\Models\Comment;
use Input, Redirect, Sentry, Str, View, Notification;
class DashboardController extends \BaseController {
public function index()
{
$post = Post::find(3)->comments()->comment;
print_r($post);die;
}
}
我认为我的数据库已正确链接,但现在我收到错误“找不到类注释”。对这个有什么建议吗?