symfony/http-foundation 5.2 changed their automatic dot to underscore translation in inputs. However, now you can't seem to access the inputs using Laravel.
Both of these tests are using the same Laravel version.
With symfony/http-foundation 5.1.9
false // has('test.here)
null // input('test.here')
true // has('test_here')
"testing" // input('test_here')
array:1 [
"test_here" => "testing"
]
With symfony/http-foundation 5.2.0
true // has('test.here)
null // input('test.here')
false // has('test_here')
null // input('test_here')
array:1 [
"test.here" => "testing"
]
There is now no way of accessing this input
Example controller code:
class UserController extends Controller
{
public function index(Request $request)
{
dd(
$request->has('test.here'),
$request->input('test.here'),
$request->has('test_here'),
$request->input('test_here'),
$request->all(),
);
}
}
Unit test to trigger
class ExampleTest extends TestCase
{
public function testExample()
{
$response = $this->get('/route?test.here=testing');
}
}
I can confirm that this behavior was changed. I'll pick this up with the Symfony team.
I think this PR is what's causing it: https://github.com/symfony/symfony/pull/37272
I talked to the Symfony team about this and this is actually a bug fix. Before it wasn't possible to retrieve inputs with a dot notation directly. But now it is.
We're also looking into why input('test.here') isn't returning the input. Thanks
We're also looking into why input('test.here') isn't returning the input. Thanks
Is there an issue I can track for that part?
There's no issue for that atm as this has always been the same behavior.
That's what this issue was for though. Since the Symfony change (which I think was a fair bug fix), the framework is unable to read inputs with dots.
I'll re-open this and take a look soon.
Yeah so ->input( uses data_get under the hood for array based keys and JSON nesting. So this doesn't works for keys using dot in their notation. You'll need to use ->get( instead.
See https://laravel.com/docs/8.x/requests#retrieving-an-input-value


@driesvints Apologies for the delay, but I think there is still an issue.
When running via unit tests (like my example above), it stays as a dot.
When running via a web server (or artisan serve), it gets converted to the underscore.
In both instances, I'm just doing looking at $request->all().
@giggsey you're probably running different PHP versions for those or have different dependencies installed. Please try a support channel.
Same PHP version, same code base.
I'll keep digging later today/tomorrow, but my current findings are that PHP converts dots to underscores in _GET. Running via unit tests calls http-foundations Request::create, which calls HeaderUtils::parseQuery from https://github.com/symfony/symfony/pull/37272.
When running via the web, Request::createFromGlobals() is used instead (_GET), and HeaderUtils::parseQuery is never called.
Confirmed that Symfony does the same, so I've reported it their side.
Thanks for the help @driesvints
Thanks @nicolas-grekas!