2

I have added this to the Controller:

public function updateMethod(Request $request)
{
   $i = 1;
   dd($request->input_name_1);
}

Now I wanted to change to this:

public function updateMethod(Request $request)
    {
       $i = 1;
       dd($request->input_name_$i);
    }

But I get this error:

syntax error, unexpected '$i' (T_VARIABLE), expecting ')'

So how can I add my custom variable to $request properly?

0

2 Answers 2

2

You can add custom variables by using bind string in one variable and passing it to $request-> like below code

$i = 1;
$tmp  = "input_name_".$i;
dd($request->$tmp);

using this you can get values of custom variables

Sign up to request clarification or add additional context in comments.

Comments

1

You can just use basic concatenation in this code. like this one.

public function updateMethod(Request $request)
{
   $i = 1;
   dd($request->"input_name_".$i);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.