thedevdojo / voyager

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

Relationship not work with Model inside Models folder #5171

Closed nguyenthanhhungbt1905 closed 3 years ago

nguyenthanhhungbt1905 commented 3 years ago

Version information

Description

When i create relationship in admin panel -> if my model file stored in folder App\Models relation will not success -> If i move model file back to folder App, it will success

dissolvdgrl commented 3 years ago

I'm experiencing the exact same problem. Tried to add a belongsTo relationship in my posts table, where Post belongs to Category. In my case I'm using Post and Category.

In my Post.php model file which resides in app/Models directory, I have namespace App\Models; instead of namespace App;.

I fixed it by editing the BREAD for my posts table and created a relationship like this: Screenshot_2021-03-08 Edit BREAD for posts table

The fully qualified model name had to be changed in my case: App\Models\Category instead of App\Category

MrCrayon commented 3 years ago

That's not a bug or a problem, Voyager form asks for "Fully Qualified Model Name (ex. App\Category)"

Usually by default Models in Laravel were created in App, since Laravel 8 default folder is App\Models anyway wherever you want to save your Models you need provide the correct fully qualified name.

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.