Let me add, why is this happening. Your requirement is that you need to reference parentid as the rvalue of where. However, in laravel, the rvalue of where cannot be sql, but can only be regular data structures, such as strings, values, time, etc. It cannot be a field name (users.id) or something with SQL function. This is to prevent SQL injection.
So, you can only use the raw method mentioned by @ty0716 to execute native sql.
Method 1
Method 2
@ty0716 is the standard answer.
Let me add, why is this happening.
Your requirement is that you need to reference parentid as the rvalue of where. However, in laravel, the rvalue of where cannot be sql, but can only be regular data structures, such as strings, values, time, etc. It cannot be a field name (
users.id
) or something with SQL function. This is to prevent SQL injection.So, you can only use the raw method mentioned by @ty0716 to execute native sql.
No one knows?