Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
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:

 public function printpreviewingredients($MealPlan_ID)
     {

//contains the value
$ingredientsid = $MealPlan_ID;

return view('MealPlanDisplay.printpreviewingredientslist', compact('ingredientsid'));

The button with URL:

  <div class="d-flex justify-content-end mb-4">
              <a class="btn btn-primary" href="{{ url('/printpreviewingredients/pdf/$ingredientsid') }}">Export to PDF</a>
          </div>

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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:

href="{{ url('/printpreviewingredients/pdf/'.$ingredientsid) }}"

Instead of:

href="{{ url('/printpreviewingredients/pdf/$ingredientsid') }}"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!