I am making a school project and I am following a video from codecourse and he uses laravel-adjacency-list, I installed it and when I try to write it in the same way he does I get this :
SQLSTATE: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'recursive `laravel_cte` as ((select *, 0 as `depth`, cast(`id` as char(65535)) a' at line 1 (SQL: with recursive `laravel_cte` as ((select *, 0 as `depth`, cast(`id` as char(65535)) as `path` from `objects` where `objects`.`id` = 9) union all (select `objects`.*, `depth` - 1 as `depth`, concat(`path`, ., `objects`.`id`) from `objects` inner join `laravel_cte` on `laravel_cte`.`parent_id` = `objects`.`id`)) select * from `laravel_cte`)
ancestorsAndSelf(): The model's recursive parents and itself.
My code :
His code :
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
You don’t always have to blame the code.
The error is because your MySQL version doesn’t have a recursive CTE feature. You need to upgrade MySQL version to 8.0 or later.
Common table expression or CTE only available in MySQL version 8.0 or later. You should have the right version of MySQL installed.
- SQL Server