Skip to content
Advertisement

Button on a view with a href that has a variable passed in the route?

I would like a button’s url to take it to a page with a ID in the URL.

Controller:

JavaScript

The button with URL:

JavaScript

Despite the value $ingredientsid not being blank, it still won’t place the value in the URL link. How can I pass a variable from the Controller method into a button url? I can get it working in a table with a @foreach loop, but presentation wise it doesn’t look right.

Advertisement

Answer

You must concatenate the variable, don’t use PHP inside of the single quote mark. When you use a single quote mark all the content inside of it is takes as string, even if you use PHP syntax.

Use:

JavaScript

Instead of:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement