课堂评论没有发现Laravel 4 [英] Class Comment not found Laravel 4

查看:144
本文介绍了课堂评论没有发现Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图向我的laravel应用添加评论系统。
但是我似乎无法让它工作。
我有两个模型


  class Post extends \Eloquent {

protected $ table ='职位';

public function comments()
{
return $ this-> hasMany('Comment','postId');
}
}

和我的评论模型


 类注释扩展\Eloquent {

protected $ table ='comments';

public function post()
{
return $ this-> belongsTo('Post');
}

}

在我的DashBoardController我正在尝试从模型中获取输出


 使用App \Models\Post; 
使用App \Models\Comment;
使用Input,Redirect,Sentry,Str,View,Notification;

class DashboardController extends \BaseController {
public function index()
{
$ post = Post :: find(3) - > comments() >评论;
print_r($ post); die;
}
}

我认为我的数据库已正确链接,但现在我'得到错误
'没有找到类注释'。
任何关于这个的建议?

解决方案

首先尝试这个:composer dump-auto(由user1669496评论) / p>

如果这没有帮助,那么改变你的模型...



更改这个:

  return $ this-> belongsTo('Post'); 

像这样:

  $ this-> belongsTo('App \Models\Post'); 

为Post模式做类似。



只需将App \Models\XXXX更改为您的邮箱模式保存的命名空间。



我有类似的问题,这有助于我,希望它能帮助您。


Im trying to add a comment system to my laravel app. But I can't seem to get it working. I have two models

class Post extends \Eloquent {

protected $table = 'posts';

public function comments()
{
    return $this->hasMany('Comment','postId');
}
}

and my Comment model

class Comment extends \Eloquent {

protected $table = 'comments';

public function post()
{
    return $this->belongsTo('Post');
}

}

in my DashBoardController I'm trying to get the output from the models

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;
}  
}

I think my database is properly linked, but now I'm getting the error 'Class Comment not found'. Any advice on this one?

解决方案

First try this: composer dump-auto (as commented by user1669496)

if this didn't helped then change your model...

Change this:

    return $this->belongsTo('Post');

to smth like this:

    $this->belongsTo('App\Models\Post');

Do the similar for Post model.

Just change App\Models\XXXX to your namespace where you have Post model saved.

I had similar problem and this helped me, hope it will help you.

这篇关于课堂评论没有发现Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆