Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add variable to $request

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

syntax error, unexpected ‘$i’ (T_VARIABLE), expecting ‘)’

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading