Avatar of Bruce Gust
Bruce Gust
Flag for United States of America asked on

How do I incorporate a # dynamic in a Laravel route?

I've got a page with a list of testimonials and at one point on the site, I have this:

<a href="testimonials#{{$test->id}}">read more...</a>

The idea being that when the user clicks on the link, they're taken to the http://nomas.site/testimonials#2 and advanced to the testimonial with the id of 2.

I've got that particular testimonial listed with a <a name="2"></a> like you would expect but it doesn't seem to work.

Any ideas?

Avatar of undefined
Last Comment
Bruce Gust

8/22/2022 - Mon
Chris Stanyon

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bruce Gust

Everything is on my local box right now, but the link looks like this:


Now, something's happening because the page does advance to a position other than the top of the content, but it's the same position every time which is what lead me to believe that something was "off."

If you're telling me that everything looks good from you standpoint, I'll go back and pop the hood on this and see if I'm not missing something obvious. My biggest concern was that there might be something within the Laravel paradigm that required a special accommodation for a route followed by a "#" character.
Chris Stanyon

OK Bruce,

No ... nothing special in Laravel and your code looks good.

Like I said, view the source of the page that contains the links to make sure they're all working properly, and then view the source of your testimonials page so make sure the <a> tags have their name set correctly.

FYI - you don't have to use an empty <a> tag for this - it'll work just as well with an ID on an element, such as a DIV.

<div id="1">

<div id="2">

Open in new window

Bruce Gust

I figured it out, Chris!

The # dynamic was working. The problem was that the content of the page would go all the way to the top of the page behind the header portion so you couldn't see / tell what was going on.

Bottom line: I got it done!

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck