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

How can I manipulate input values? #679

Open
benfiratkaya opened this issue Aug 14, 2023 · 1 comment
Open

How can I manipulate input values? #679

benfiratkaya opened this issue Aug 14, 2023 · 1 comment

Comments

@benfiratkaya
Copy link

I have code like that:

function input($index = null, $defaultValue = null, ...$methods)
	{
		if ($index !== null) {
			return request()->getInputHandler()->value($index, $defaultValue, ...$methods);
		}
		
		return request()->getInputHandler();
	}
if (input("stockStatus") == 0) {
    $_POST["stock"] = -1;
}
echo input("stock");

I want to make "stock" value "-1" when "stockStatus" is 0. But the "stock" value does not change.

How can I set post value?

@skipperbent
Copy link
Owner

You are not supposed to change super global variables, they contain values parsed and specific to the the request so that is not supported. If you need to manipulate the values and use them later on in your code, you should move them to your own custom variables. The request helper class supports custom variables and is available on everywhere, so you could always take advantage of that:

request()->stock = input('stockStatus', 0);

request()->stock // equals 0

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

No branches or pull requests

2 participants