Snapey

php variable function

Posted 1 year ago by Snapey

I have this ugly bit of code but can't seem to find the right syntax to simplify it

    $r=$request->response;
    $this->$r($task);

$request->response is a string corresponding to one of three buttons on a form. The buttons have values of 'approve', 'query' and 'refuse'

in the snippet I am trying to call a function that has the name specified in the request. So, if the user presses 'approve' then $this->approve() is called

I tried $this->$request->response($task); but the syntax is not right.

it works as I have it now but it's annoying me everytime I see that $r variable

and, yes, my form request validates that response can only be one of the three method names.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.