Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Refactor get method to use data_get for query payload retrieval #55003

Draft
wants to merge 1 commit into
base: 12.x
Choose a base branch
from

Conversation

basantashubhu
Copy link

@basantashubhu basantashubhu commented Mar 13, 2025

Refactored the get method to replace the parent class method call with data_get, which retrieves the query payload item from the request using the input source. This improves flexibility in handling the request data.

Wanted something like:

  $request->get('user.name');

Found that get method does not support dot syntax to access data.

Changes:

    public function get(string $key, mixed $default = null): mixed
    {
        return data_get($this->getInputSource()->all(), $key, $default);
    }

Refactored the get method to replace the parent class method call with data_get, which retrieves the query payload item from the request using the input source. This improves flexibility in handling the request data.
@basantashubhu basantashubhu changed the title Refactor get method to use data_get for query payload retrieval [12.x] Refactor get method to use data_get for query payload retrieval Mar 13, 2025
@crynobone crynobone marked this pull request as draft March 13, 2025 06:22
@crynobone
Copy link
Member

crynobone commented Mar 13, 2025

Tests are failing

@fragkp
Copy link
Contributor

fragkp commented Mar 13, 2025

The ->get() method should not be used in userland as the doc block says: "This method belongs to Symfony HttpFoundation and is not usually needed when using Laravel".

Copy link

@Charlesnorris509 Charlesnorris509 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using ' public function get(string $key, mixed $default = null): mixed
{
return data_get($this->getInputSource()->all(), $key, $default);
} You could make call directly wirh the database, however proper security needs to be configurated as DB table name would be exposed in the code

@fragkp
Copy link
Contributor

fragkp commented Mar 18, 2025

@Charlesnorris509 This PR has nothing do with DB calls. The request input could be used anywhere.

@Charlesnorris509
Copy link

@Charlesnorris509 This PR has nothing do with DB calls. The request input could be used anywhere.

Thank you. You letting me know i'll re-read the code to improve my understanding

@morloderex
Copy link
Contributor

Why use get over input? You can pass dot notation as the first parameter to input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants