Creating my First ReportWidget

Ok im building my First widget,
i followed the documentation, and i actualy can add my widget to the Dashboard,
But when i refresh is gone.
If i add the widget again and i edit the setting like the Width i got an error screaming:
“The specified widget is not found.”

But i just added it to the Dashboard??

Has anyone had the same problem and solved it?

Hi @codeskullz ,

It did happen to me but I don’t recall why and how I solved it. I have in mind the $defaultAlias variable.

You have it set?

Hi @apinard, Thank you for your reply to my message

Yes, I also see in the database that this is added. I have checked the code 3 times but either I am missing something or I just don’t know.

@codeskullz , remove the validation part and see if it works:

'validation' => [
                    'required' => [
                        'message' => 'The Name field is required'
                    ],
                    'regex' => [
                        'message' => 'The Name field can contain only Latin letters.',
                        'pattern' => '^[a-zA-Z]+$'
                    ]
                ]

I think it was the reason. Because it doesn’t respect the regex if you don’t enter anything

Unfortunately that didn’t work. I’ll look at it again later. Thanks in advance

looks strange, because i copied your code (removed some models based things to work without any data) and it shows correctly.

can you paste a _widget partial code too?

i used to create a new widget.

php artisan create:reportwidget nielsvandendries.therantzone TestWidget

I didnt change any code only added it to the Plugin.php to regsiter.
I got exaclty the same issue.

    public function registerReportWidgets()
    {
        return [
            'NielsVanDenDries\Therantzone\ReportWidgets\TotalRants' => [
                'label'   => 'Total Rants',
                'context' => 'dashboard',
                'permissions' => ['nielsvandendries.therantzone.therantzone_manager']
            ],
            'NielsVanDenDries\Therantzone\ReportWidgets\TestWidget' => [
                'label'   => 'Test Widget',
                'context' => 'dashboard',
                'permissions' => ['nielsvandendries.therantzone.therantzone_manager']
            ],
        ];
    }

I can even see it is added to the database table “backend_user_preferences”.

I even pushed it to my production environment, (thats a diffrent OCT installation) but still the same.

@codeskullz I think it might be the namespace.

you have in Plugin.php:

NielsVanDenDries\Therantzone\ReportWidgets\TotalRants

and you namespace that is set in your reportwidget is:

Nielsvandendries\Therantzone\ReportWidgets;

Try:

  public function registerReportWidgets()
    {
        return [
            'Nielsvandendries\Therantzone\ReportWidgets\TotalRants' => [
                'label'   => 'Total Rants',
                'context' => 'dashboard',
                'permissions' => ['nielsvandendries.therantzone.therantzone_manager']
            ],
        ];
    }

If not, adding debug points and stepping through the files should help pinpoint where the issue lies.

@apinard omg that did the job, how did i not see that.
Thank you for you support @apinard and @snipi

1 Like