->getRelated for menu didnt work.

I follow this manual https://twillcms.com/guides/page-builder-with-blade/adding-navigation.html I do all the thinks which is there, I do some links to my pages in twill I will be see a relatitons in twill table
MariaDB [laravel]> select * from twill_related;
+----+------------+-------------------------+------------+-----------------+--------------+----------+
| id | subject_id | subject_type | related_id | related_type | browser_name | position |
+----+------------+-------------------------+------------+-----------------+--------------+----------+
| 1 | 2 | App\Models\MenuPageLink | 7 | App\Models\Page | page | 1 |
| 2 | 3 | App\Models\MenuPageLink | 8 | App\Models\Page | page | 1 |
| 3 | 4 | App\Models\MenuPageLink | 6 | App\Models\Page | page | 1 |
MariaDB [laravel]> select * from twill_related;
+----+------------+-------------------------+------------+-----------------+--------------+----------+
| id | subject_id | subject_type | related_id | related_type | browser_name | position |
+----+------------+-------------------------+------------+-----------------+--------------+----------+
| 1 | 2 | App\Models\MenuPageLink | 7 | App\Models\Page | page | 1 |
| 2 | 3 | App\Models\MenuPageLink | 8 | App\Models\Page | page | 1 |
| 3 | 4 | App\Models\MenuPageLink | 6 | App\Models\Page | page | 1 |
But when I call in compoment $link->getRelated('page')->first()->slug}} I have this error Attempt to read property "slug" on null In my code. The MenuPageLink.php is use HasRelated; In MenuPageLinkRepository.php is
protected $relatedBrowsers = ['page']; and use HandleNesting; In MenuPageLinkController is $form->add(Browser::make()->name('page')->modules([Page::class])); I didnt understod what is wrong and why the getRelated() didnt get the relations. Thx for answer
Twill
2 Replies
bohous
bohousOP2y ago
So the solution is make a left join and forget those browsers feauture.? I make controll , but all my code is to same which is on guide page. But didnt work. Have somebody other solution, or find where is a bug.?
ifox
ifox2y ago
Hi @bohous you definitely don't need a manual left join. What is the $link variable in your snippet? Try to dd the result of getRelated('page')
Want results from more Discord servers?
Add your server