VentureCraft / revisionable

Easily create a revision history for any laravel model
http://twitter.com/duellsy
MIT License
2.56k stars 348 forks source link

Display revisions in Laravel Nova #429

Closed wajdijurry closed 1 year ago

wajdijurry commented 1 year ago

I am absolutely confident with this package, on the other hand, I would like to display revisions in Laravel Nova dashboard v4.0.

I am doing this for now:

class Product extends Resource {
    public function fields()
    {
        return [
            new Panel('Revisions', [
                MorphMany::make('Revisions', 'revisionHistory', \App\Nova\Revision::class),
            ]),
        ]
    }
}

I have Revision resource as well:

class Revision extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = \Venturecraft\Revisionable\Revision::class;

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'id';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id',
    ];

    /**
     * Hide from navigation menu
     *
     * @var bool
     */
    public static $displayInNavigation = false;

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function fields(NovaRequest $request)
    {
        return [
            MorphOne::make('Actor', 'userResponsible', \App\Nova\User::class),

            Text::make('Field', 'key'),

            Text::make('Old Value', 'old_value'),

            Text::make('New Value', 'new_value')
        ];
    }

// opt-out code

All works fine except userResponsible attribute, which resolves to a model \App\Models\User after requesting revisionHistory . How can I display User in my nova Resource?

An image to demonstrate the current display: image

anditsung commented 1 year ago

userResponsible did not return the relation. maybe create a new class that extend Revision then return user relation?

wajdijurry commented 1 year ago

@anditsung Yes, and that's what I did. I extended the Revision model and defined a user relation. Now, I am able to display the user in revisions table.

Thanks!