nova-comments icon indicating copy to clipboard operation
nova-comments copied to clipboard

Commenter doesn't work

Open cja-github opened this issue 4 years ago • 6 comments
trafficstars

The Commenter resource tool loads no comments with a 409 and 404s on submitting a new comment.

Loading makes a request to http://127.0.0.1:8000/nova-api/comments?page=1&orderBy=created_at&orderByDirection=desc&viaResource=issues&viaResourceId=4&viaRelationship=comments&relationshipType=hasMany and throws Symfony\Component\HttpKernel\Exception\HttpException at \vendor\laravel\framework\src\Illuminate\Foundation\Application.php:1116 https://flareapp.io/share/J7oj2odP?error=J7oj2odP&owner_token=Z9rRtT9iV2S0HkeKk60A6GngRV1udzCF#F60L1116

Submitting a new comment 404s on http://127.0.0.1:8000/nova-api/comments

I installed as follows:

composer require kirschbaum-development/nova-comments php artisan migrate

use Commentable; in my model and new Commenter(), in the fields function of the Nova resource.

The CommentsPanel works, but it's not worth having this package just for that, especially as there's no image/attachment functionality.

cja-github avatar Jun 02 '21 10:06 cja-github

Running into the same issue. Using Laravel 7 and Nova 3.23.1.

neelmehta avatar Jun 27 '21 16:06 neelmehta

It can be solved by adding an association in the resource. Should be like this HasMany::make('Comments').

rifeman2007 avatar Jun 30 '21 04:06 rifeman2007

This seems to work for me.

The error seems to be due to the fact that your commentable resource has to have not only Laravel relation (in the model) but also a field like HasMany, as mentioned by comment up to. For that to work you need to create a Nova resource and address it in your commentable resource.

app/Nova/Comment.php

<?php

namespace App\Nova;

use KirschbaumDevelopment\NovaComments\Nova\Comment as NovaComment;

class Comment extends NovaComment
{

}

The resource you need comments on:

//...
/**
     * Get the fields displayed by the resource.
     *
     * @param  Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
			//...
            \KirschbaumDevelopment\NovaComments\Commenter::make(),
            HasMany::make('Comments', 'comments')->hideFromDetail()->hideFromIndex(),
			//...
		];
	}
//...

Maybe theres a better way to do it, but i did not find that.

fosron avatar Sep 03 '21 15:09 fosron

Just for the record, you dont need to create a new Nova resource, you can just add the class of in the package, like this:

HasMany::make(__('Comments'), 'comments', \KirschbaumDevelopment\NovaComments\Nova\Comment::class)->hideFromDetail()->hideFromIndex(),

ghost avatar Apr 28 '22 06:04 ghost

is this package still active and accepting PR?

anditsung avatar Jun 21 '22 05:06 anditsung

@anditsung It is still active, sorry about the delays in responding. We've recently updated the package to support Laravel Nova v4 thanks to another contributor.

@cja-github I have replicated this error locally, I'm curious what the best solution would be. Perhaps we shouldn't rely on the /nova-api/... endpoints for retrieving and posting comments? I don't think the installation experience will feel very good if you must include the related HasMany field manually in any resource that is commendable.

Any thoughts from anyone?

adammparker avatar Nov 12 '22 23:11 adammparker