laravelista / comments

Native comments for your Laravel application.
MIT License
744 stars 142 forks source link

Comments are not displayed #145

Closed EricTalv closed 3 years ago

EricTalv commented 3 years ago

Hello Again!

I am trying to include this package to my project and Initially I tried to do it by the book, that didn't work as it shows the error referenced in my last post here #144.

Now I thought I solved it by instead of giving my Commentable model I gave the user instead,

Now the commenting section is displayed and I can comment, when I submit a comment it comes to my database, but no comments are ever displayed, it's always showing the default "no comments yet" message.

What should I do?

mabasic commented 3 years ago

Here you need to pass the commentable model

comments(['model' => $book])

The user model should have the Commenter trait.

The Book model in this example, would need to have Commentable trait.

Check the config comments.php if you use custom location for models.

EricTalv commented 3 years ago

Well I added everything needed, my Article model has Commentable and User has Commenter.

The comments are coming to my database if I use $article->user but are not getting displayed.

If I only pass the Commentable Model I get the strange error referenced in my last post.

mabasic commented 3 years ago

I will need to verify this, but something looks funny in your previous issue. Can you reopen it?

whakru commented 3 years ago

I also do not show comments, although they are in the database. I call it like this: @comments(['model' => $post])

my Post.php it looks like this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravelista\Comments\Commenter;

class Post extends Model
{
    use Commenter; 

    protected $table = 'topcashback';

    protected $fillable = ['id', 'name'];

}

the page call looks like this:

public function CashBackInfo(Post $post,Request $r, $service) {
$cashbacksite = DB::table('topcashback')->where('name', $service)->get();
$info = 1;
$post = $post->first();
return view('pages.top.CashBackInfo', compact('cashbacksite', 'info', 'post')); 
    }   

The data is sent to the database: image

But it doesn't output them image

Is there even an option to avoid the model? For example, specifying the category and id of the record? For example @comments(['category' => 'shops', 'id' => "1"])

QBLes commented 3 years ago

I also do not show comments, although they are in the database. I call it like this: @comments(['model' => $post])

my Post.php it looks like this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravelista\Comments\Commenter;

class Post extends Model
{
  use Commenter; 

  protected $table = 'topcashback';

  protected $fillable = ['id', 'name'];

}

the page call looks like this:

public function CashBackInfo(Post $post,Request $r, $service) {
$cashbacksite = DB::table('topcashback')->where('name', $service)->get();
$info = 1;
$post = $post->first();
return view('pages.top.CashBackInfo', compact('cashbacksite', 'info', 'post'));   
  }   

The data is sent to the database: image

But it doesn't output them image

Is there even an option to avoid the model? For example, specifying the category and id of the record? For example @comments(['category' => 'shops', 'id' => "1"])

So i had this issue i found my problem was i not using "use Laravelista\Comments\Commentable;" i messed up and never noticed i added "use Laravelista\Comments\Commenter;" so maybe double check :)

whakru commented 3 years ago

So i had this issue i found my problem was i not using "use Laravelista\Comments\Commentable;" i messed up and never noticed i added "use Laravelista\Comments\Commenter;" so maybe double check :)

Heu. it really worked! Thanks!!!

used use Laravelista\Comments\Commentable; use Commentable; Instead of use Laravelista\Comments\Commenter; use Commentable;

mabasic commented 3 years ago

It is solved now?

whakru commented 3 years ago

It is solved now?

I have, yes

EricTalv commented 3 years ago

I double checked the commentable and commenter fields but these are fine, I am still getting the error on #144 , I tried opening a re-production on a different laravel project but on there seems to work fine, so this is definitely unique to my project. Perhaps you can take a look at it here https://github.com/EricTalv/laravel-blog.

my stack trace goes here:

  if (isset($approved) and $approved == true) {

        $comments = $model->approvedComments;

    } else {

 -err->       $comments = $model->comments;

    }

No idea what could be causing this :s

mabasic commented 3 years ago

Uhh.

This should not be here: https://github.com/EricTalv/laravel-blog/blob/master/app/Article.php#L49-L52

This entire model is not needed: https://github.com/EricTalv/laravel-blog/blob/master/app/Comment.php#L21

Try deleting those two and see if it works.