0

In a API endpoint taking "emails" as an array, I am validating values with a Request Class. In this Request class' prepareForValidation method:

$this->merge([
    'emails' => array_unique($this->emails)
]);

I have this lines. And a controller like this:

foreach ($request->get('emails') as $email) {
    //process
}

In local environment, I have no error or bug. It works expected. I am giving "aaa@bbb.com" twice, and it works only once. But in server (with octane, no other changes), when I give "aaa@bbb.com" twice again, it works twice.

I have finally solved the problem with using

$request->input()

instead of "$request->get()". But I am curious, why $request works fine in local but causing problems in server? Is it related to Octane? Has anyone encountered such a problem before?

Alper
  • 152
  • 1
  • 7
  • Is this a json request? are you running it exactly the same production / local – mrhn Sep 05 '22 at 13:42
  • @mrhn Not "exactly", local on mac valet and server in ubuntu nginx. But not mentionable differences. Same db, same tools. Only difference is Octane. Yes, JSON request. – Alper Sep 05 '22 at 13:46
  • @lagbox thank you for your helpful comment. But I still cannot understand why its working as expected without octane in local. Interesting situation – Alper Sep 06 '22 at 08:54
  • 1
    sorry I need to correct that comment ... `get` has a different priority of which input bags it will check first compared to `input` (not that it only checks the query parameters, i was thinking of the `query` method), when dealing with validation it uses `input` to get the inputs [you want to be using the `input` method for dealing with inputs instead of `get`].... I will think on the implications of octane though for your situation – lagbox Sep 06 '22 at 18:56

0 Answers0