thedevdojo / chatter

Chatter is a Simple Laravel Forum Package
https://devdojo.com/forums
MIT License
900 stars 294 forks source link

Cant seem to get discussions off category #194

Closed firescript closed 6 years ago

firescript commented 6 years ago

I'm just building a simple discussion management backend for chatter in my app. In the controller i'm passing down:

        $categories = Category::all();
        $discussions = Discussion::all();
        $posts = Post::all();

        return view('admin.discussions.discussion-index')
            ->with('categories', $categories)
            ->with('discussions', $discussions)
            ->with('posts', $posts);

When I try and access the discussions off category model from inside a $categories for loop {{dd($category->discussions)}}

I get this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'chatter_discussion.category_id' in 'where clause' (SQL: select * from `chatter_discussion` where `chatter_discussion`.`category_id` = 1 and `chatter_discussion`.`category_id` is not null and `chatter_discussion`.`deleted_at` is null) (View: /home/vagrant/Code/machealth/resources/views/admin/discussions/discussion-index.blade.php)
firescript commented 6 years ago

to fix I had to extend the Category class into my own app, then change the discussions method in Category model from:

    public function discussions()
    {
        return $this->hasMany(Models::className(Discussion::class));
    }

TO

    public function discussions()
    {
        return $this->hasMany('DevDojo\Chatter\Models\Discussion','chatter_category_id','id');
    }
marktopper commented 6 years ago

We are open to pull requests with this 👍 Thanks

firescript commented 6 years ago

Sent in the PR - closing this issue.