Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Azirius's avatar
Level 12

Laravel & Laravel-Nestedset Issues

Hey guys!

I'm attempting to fix this issue I'm having with my hobby project, not sure if anyone can help or if I'm really okay to ask for help, however, I'm gonna give it a go because I got closed down on the Laravel GitHub and I can't get a response on StackOverflow, so, thought I'd try the Laracasts community!

Anyway, on to my issue!

I'm not sure whether its an issue with my code or Laravel 5.3 or a bug... but for some reason I cannot issue updates to the order of the nodes. I can edit them fine via the terminal (i.e. artisan tinker), and inserting them is also fine, however trying to update, no luck.

I've tried several things, to see if I can locate the source of the issue. I think I've found it: Query ROLLBACK is found within my MySQL logs, this is present only when issuing an update via the web interface...

It's a tad confusing, to be honest.

Here is the code updating the node:

Link::rebuildTree($request->order);

Link is an Eloquent Model that uses the NodeTrait from the laravel-nestedset package. The $request->order is a client-side generated order of nodes to update the current order.

I did have it working prior to upgrading to Laravel 5.3 and is now present. I cannot see what changes to the Eloquent side of Laravel would have caused this bug... I've even reverted back to Laravel 5.2 to make sure this isn't something my end. Nope, 5.2 works fine, 5.3 breaks. I'm at a loss on how to work around this...

Thanks in advance, and any other information I can give please don't hesitate to ask :D I am just not sure what other information would be pertinent for the issue I'm having, and it seems peculiar, considering it works fine on Laravel 5.2 but not on 5.3 :S

0 likes
5 replies
MikeHopley's avatar

Maybe you could try the down() or up() methods to shift the order of a node, instead of replacing the (sub)tree with rebuildTree().

Alternatively use Baum, which has more helpful methods such as moveToLeftOf($otherNode). I'm using Baum, but I haven't yet moved to Laravel 5.3.

Azirius's avatar
Level 12

I have tried the Baum library and that too and unfortunately didn't quite meet the requirements. The use case also allows for placement above/below and a child of a node, which also doesn't work, and again is via the web interface. I mean the thing works when issued via artisan tinker through the CLI but any time I try via the web that ROLLBACK pops up in the MySQL logs, and it's not throwing any errors, it's completely silent, but it's only when I'm using Laravel 5.3, rolling back to 5.2 works. I could rollback because theres no issues with Laravel 5.2, but because it's also a hobby project I'd like it run the latest & greatest and actually deal with the issue.

There's nothing I can see that would break it, here's the SQL query being issued that's being captured via Laravel Debugbar:

update links set _rgt = ?, updated_at = ? where id = ?

and, here is the data being put in to the prepared statement:

[4,"2016-08-31 18:41:02",1]

As far as I can see the SQL query is not malformed.... So, again the ROLLBACK is a bit... Strange...

Edit: Removed backticks as causing issue with Mark Down

MikeHopley's avatar

That is very strange.

I'm afraid I have no idea what's going on, but I've a nasty feeling I might run into this issue too once I upgrade Laravel. :(

One thought: why are you using Laravel 5.3 so soon after release? I mean, I know it's officially "production ready", but we all know that's not how software works.

Unless you have a burning desire to use some new feature from 5.3, why not wait a few months? Inevitably the community will discover bugs or undocumented issues, and packages will get updated too. Let them do the work so you don't have to.

I'm not saying this will fix the issue, but it might. Take the lazy route. ;)

Azirius's avatar
Level 12

Oh, no real reason really, mainly because I migrated to 5.3 and out of stubbornness I don't really want to migrate back, hahaha....

I mean, I'll keep at it as there's no timeline to it as it's not gonna be ever released or anything, I just code in my spare time, so while mildly annoying it is just gonna have to stay like it until either a fix is rolled out or find that I've made a mistake somewhere!

Azirius's avatar
Azirius
OP
Best Answer
Level 12

I have apparently found the root cause for the error, it is indeed an issue with the library in where on of the events was returning a null value (which I assumed get's evaluated to false by Laravel).

So I've raised an issue of the GitHub page and made a small temporary fix myself until it gets patched out correctly, not sure if my fix will effect any of the other library functionalities :P

Thanks for all the comments though! If any one suffers from the same issue, feel free to ask and I will 'enlighten' them with my fix :D

1 like

Please or to participate in this conversation.