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

Override Activitylog resource #5

Closed
7krasov opened this issue Jun 26, 2019 · 4 comments
Closed

Override Activitylog resource #5

7krasov opened this issue Jun 26, 2019 · 4 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@7krasov
Copy link

7krasov commented Jun 26, 2019

Hi! Thanks a lot for this nova package!
Could you please help me to override your Activitylog resource? Trying within NovaServiceProvider or my custom service provider - no success...
I would override fields method to output user name instead of id, but can't find the way. Maybe you could help...

Thanks!

@bolechen bolechen self-assigned this Jun 26, 2019
@bolechen
Copy link
Owner

You my look the Customize section in the README file, create your owner resource file extends the original like this and override the fields method:

class Activity extends Activitylog
{
//...

    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Text::make('Description'),
            Text::make('Subject Id'),
            Text::make('Subject Type'),

            Text::make('Causer', 'causer_id')->displayUsing(function ($user_id) {
                return \App\User::find($user_id)->name;
            }),

            Text::make('Causer Ip', 'properties->ip')->onlyOnIndex(),
            Code::make('properties')->json(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE),
            DateTime::make('created_at'),
        ];
    }

//...
?>

@7krasov
Copy link
Author

7krasov commented Jun 27, 2019

Got it! :-) I tried just to "rebind" a resource with the inherited, with the same name via Laravel DI instead of getting a new name and override it within config...
Works as you said, thank you 👍

@paul-muckypuddle
Copy link

I'm having a similar problem but I think I'm missing something:

  • I've created a resource, Customactivitylog, in the app/Nova directory, that overrides Activitylog from your package
  • But I'm not sure what config value to provide?

@paul-muckypuddle
Copy link

Sorry, for some reason Nova wasn't registering the new resource. For other folk, adding:

protected function resources()
{
    parent::resources();
    Nova::resources([
        \Yourcustomactivitylog::class
    ]);
}

to NovaServiceProvider.php then using the resource name yourcustomactivitylogs in the tool config will work

@bolechen bolechen added the good first issue Good for newcomers label Oct 5, 2020
@bolechen bolechen pinned this issue Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants