Hello,
I have in form two fields with key "key" (for example), and the "key" is an array.
... name="key[value1]" ...
... name="key[value2]" ...
Now, request->has can't check if request has "value2", for example:
$request->has('key.value2')
Always returns false.
Of course, I can do something like this:
isset($request->get('key')['value2'])
but I prefer "has" method.
In my opinion, support for array keys in "has" method in laravel 5.3 will be a nice gesture. :heart:
@Macsch15 but $request->has('key.value2') should work! What laravel version are you using?
Laravel Framework version 5.2.32
This test passes:
$request = Request::create('/', 'GET', ['foo' => ['bar' => 'baz']]);
$this->assertTrue($request->has('foo.bar'));
Can you please double check?
Ok, I discover something. It works fine when input passing some value, when we have, for example button with no "value", "has" returns always false.
<button name="key[value1]" type="submit">Action</button>
Returns: false
<button name="key[value1]" value="some value..." type="submit">Action</button>
Return: true
Well, that's how it's supposed to work :) It returns true on a non-empty value.
Ok, got it. Thanks for help :+1:
Most helpful comment
@Macsch15 but
$request->has('key.value2')should work! What laravel version are you using?