efectn / laravel-menu-builder

Wordpress like drag & drop menu builder for Laravel 9.x
GNU General Public License v3.0
6 stars 8 forks source link

Error After Initial Plugin Setup #9

Closed SyedUsamaHaiderKazmi closed 5 months ago

SyedUsamaHaiderKazmi commented 9 months ago

Issue: Attempt to read property ID on Null Exception At: Menu::Render()

image

artifex-media commented 9 months ago

Same issue.

efectn commented 9 months ago

Will check it soon

rafig256 commented 5 months ago

After executing the necessary commands, when I open the blade page, it gives the following error: Attempt to read property "id" on null Apparently this is because there is no data in the database yet. I fixed this error by manually adding a data to the database. But it will be better if this error is fixed automatically. Maybe writing a seed can completely solve this simple problem

SyedUsamaHaiderKazmi commented 5 months ago

Will check it soon

Hi @efectn i hope that you and all other participants finds this in good health

I am closing this issue with a solution that i implemented within the package on my localhost. Here is the details:

In the package, originally in the MenuBuilder@render() function: (at line=19) File Path= efectn/laravel-menu-builder/src/MenuBuilder.php

if ((request()->has("action") && empty(request()->input("menu"))) || request()->input("menu") == '0') { return view('menu-builder::menu-html')->with("menulist" , $menuList); }

Based on validation above,

then return view with empty values and allow user to create menu, but when the package is freshly installed, none of the validation meets and system goes to next if which tries to get the very first menu from the database table, which in reality is empty.

After carefully debugging it (atleast based on my scenario), i added a validation within the validation mentioned above, which also checks the null value.

Updated validation:

if ((request()->has("action") && (empty(request()->input("menu")) || is_null(request()->input("menu")))) || (request()->input("menu") == '0' || request()->input("menu") == null)) { return view('menu-builder::menu-html')->with("menulist" , $menuList); }

@efectn if you add this within the package and update the package, i hope it will help many new package users who are looking forward to try this awesome package!

efectn commented 5 months ago

Hi @SyedUsamaHaiderKazmi would you like to create PR for your fix? I'm so busy with other projects and i couldn't maintain this repo and so sorry about that. I will try to fix this issues weekend and perhaps refactor the ui of the extension next weeks

SyedUsamaHaiderKazmi commented 5 months ago

Hi @efectn sure, i can do that, and will do it this weekend.