thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Documentation "Overriding files" > "Voyager-Models" has lack or wrong information #5389

Closed Ronan-Lenor closed 3 years ago

Ronan-Lenor commented 3 years ago

Version information

Description

When i overide the MenuItem (but i guess the problem is the same with other files) i put in my AppServiceProvier.php

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        Voyager::useModel('MenuItem', \App\Models\MenuItem::class);

and in my \App\Models\MenuItem.php

    public static function boot()
    {
        parent::boot();

        static::retrieved(function ($model) {
            dd('retrieved');
        });
    }

sadly, the static::retrieved is never triggered.

Steps To Reproduce

  1. Then i go to the Admin panel > Tools > Menu Builder > admin .... builder

Expected behavior

output the dump "retrieved"

Additional context

but if i put Voyager::useModel('MenuItem', \App\Models\MenuItem::class); in the boot() method instead of the register(), then the static::retrieved event is triggered...

So i suggest to modify the documentation to tell to put Voyager::useModel in the boot method instead.

the ultimate goal is to be able to override MenuItem and be sure that the original $model->menu->removeMenuFromCache(); are still executed. Otherwise, we get only the menu from the cache and not from the databse.

i didn't wanted to do a PR because i have no idea if movig that Voyager::useModel from the register() to boot() would had a negative impact on the voyager package.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.