I
I
Igor Tarasov2020-09-17 09:53:37
Laravel
Igor Tarasov, 2020-09-17 09:53:37

Why doesn't Laravel's whereRaw support named placeholders like ::select?

I'd love to hear thoughts on the case, what is the reason for this. By understanding the real reason, you can design your code better.

Because you can get around this through the same ::select. But it’s not just that the developers removed such simple functionality.

Placeholders in the form ? in my opinion, they are very dangerous, since it is easy to make a mistake in the order of parameters in an array.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Wells, 2020-09-17
@itsoft

Welcome to Laravel. There is no real objective reason why they did this. Maybe they were too lazy, maybe they considered it unnecessary, maybe they don’t want to refactor and introduce such breaking changes.

S
Samuel_Leonardo, 2020-09-19
@Samuel_Leonardo

Completely Supports

User::whereRaw('username = :username',[':username'=>'test'])->get();

There are two restrictions,
1. named and positional parameters must not be used at the same time
2. named parameters must be unique
repetition will also cause an error, e.g. 'id =:id or something_else=:id'
Accordingly, if you mix whereRaw using named parameters with regular where , you will get an error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question