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

Display revisions in Laravel Nova #429

Closed
wajdijurry opened this issue Sep 25, 2023 · 2 comments
Closed

Display revisions in Laravel Nova #429

wajdijurry opened this issue Sep 25, 2023 · 2 comments

Comments

@wajdijurry
Copy link

wajdijurry commented Sep 25, 2023

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
Copy link

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

@wajdijurry
Copy link
Author

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

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

2 participants