Class Comment not found Laravel 4

 ̄綄美尐妖づ 提交于 2019-12-08 13:41:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19731097/class-comment-not-found-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!