Twill CMSTC
Twill CMS3y ago
2 replies
bohous

->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 |

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
Preview image
Was this page helpful?