Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commenter doesn't work #40

Open
cja-github opened this issue Jun 2, 2021 · 6 comments
Open

Commenter doesn't work #40

cja-github opened this issue Jun 2, 2021 · 6 comments

Comments

@cja-github
Copy link

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 cja-github changed the title Completely non-functional Commenter doesn't work Jun 2, 2021
@neelmehta
Copy link

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

@rifeman2007
Copy link

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

@fosron
Copy link

fosron commented Sep 3, 2021

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.

@ghost
Copy link

ghost commented Apr 28, 2022

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(),

@anditsung
Copy link

is this package still active and accepting PR?

@adammparker
Copy link
Member

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants