outl1ne / nova-menu-builder

This Laravel Nova package allows you to create and manage menus and menu items.
MIT License
241 stars 86 forks source link

Add a database connection to `exists:` validation #183

Open stefvanesch opened 11 months ago

stefvanesch commented 11 months ago

We are using this package for a websites that is multi tenant using the spatie package. We now have an issue where the validation if a menu exists will fail because it will check the landlord database.

return array_merge([
    'menu_id' => "required|exists:$menusTableName,id",
    // ...
])

The menu's in this case are stored in the tenant database so we need to overrule the database connection in the validation. We will create a pull request to address this issue.

KasparRosin commented 9 months ago

This seems like a valid issue, but rather rare one and easily fixable by extending our MenuBuilder tool class. Personally feel like this doesn't deserve us bloating our configuration file.

Since it's a tool class and not used internally, I recommend you extend it in your own project and call your class with updated methods inside the tools function in NovaServiceProvider class.

KasparRosin commented 9 months ago

Since it's a tool class and not used internally

I was wrong about this, we use it internally to, which complicates the solution a bit, but with relative ease you can still override the vendor class in your project.

KasparRosin commented 9 months ago

https://github.com/outl1ne/nova-menu-builder/blob/main/config/nova-menu.php#L18 @stefvanesch if you assign your table name to connection.table_name, it should already try to look up the correct database connection and table. Could you try it, I think that solves your problem the easiest.

stefvanesch commented 7 months ago

@KasparRosin sadly that didn't work for us. I'm not sure why not anymore. We've forked your package and added the changes there to make it work for our situation.