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[42000]: 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`)
Github:
ancestorsAndSelf(): The model's recursive parents and itself.
My code :
His code :
Answers:
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.
Method 1
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.
Compatibility :
- MySQL
8.0+
- MariaDB
10.2+
- PostgreSQL
9.4+
- SQLite
3.8.3+
- SQL Server
2008+
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0