TC
Twill CMSβ€’2mo ago
MAD

Position reordering not working

Hi! I am checking Twill out to see if it's a match for our next project. It looks really promising but I walked into a small problem with the first guide "Building a simple page builder with Laravel Blade". I've successfully ran through it but the section "Adding navigation" gives me a small problem, the code works fine and gives no errors or whatsoever. However, the frontend does not work. When I drag a menu item to a new position or drag it to be a child of another item the frontend will reply that the order has been changed, yet when I reload there is no change. The response of the xhr request contains: variant: 'success', it's just that the database is not updating and reflecting the changes. If I change the values in the database myself the frontend reflects those and it works nicely. But I'm not so keen on changing on positions by hand all the time πŸ˜… Can anyone point me in a direction on where to look / debug this issue? Thanks!
5 Replies
ifox
ifoxβ€’2mo ago
hi @MAD reordering in nested modules is using a queued job for data integrity. php artisan queue:work running in the background will execute them and update the database.
MAD
MADOPβ€’2mo ago
@ifox Awesome, that was it! Thank you very much, that information was absent in the guide πŸ˜… (Or I missed it) But now that we are at it, would you happen to have an idea what happens here?
No description
MAD
MADOPβ€’2mo ago
The order above is not reflected when retreiving the order like this:
$links = MenuLink::published()->get()->toTree();

$links = $links->map(function(MenuLink $link) { return $link->title; });
dd($links);
$links = MenuLink::published()->get()->toTree();

$links = $links->map(function(MenuLink $link) { return $link->title; });
dd($links);
Actual output:
Illuminate\Support\Collection {#1531 β–Ό // app/View/Components/Menu.php:31
#items: array:3 [β–Ό
0 => "Home"
1 => "About"
2 => "Plans"
]
#escapeWhenCastingToString: false
}
Illuminate\Support\Collection {#1531 β–Ό // app/View/Components/Menu.php:31
#items: array:3 [β–Ό
0 => "Home"
1 => "About"
2 => "Plans"
]
#escapeWhenCastingToString: false
}
ifox
ifoxβ€’2mo ago
Your tree might be broken because of your manual edits. And you're also supposed to call ordered() before toTree, IIRC. Check the laravel nested-set package docs. Sorry I'm on mobile. I'll make sure to update the guide with your feedback, sorry about that
MAD
MADOPβ€’2mo ago
Of course, it's a Laravel collection.. Thanks for that! It wasn't my edits (just started with new data) it was the ->ordered() call. So far so good, I'll experiment around with it some more. Thanks for the awesome work, code and project [AT]twill people!
Want results from more Discord servers?
Add your server