Arsalan Mustafa
Arsalan Mustafa

Reputation: 3

I want to make the users navigate to a point on a page when they click on a link and link are dynamically coming from database

controller is

$scroll=true;
return view('frontgoso.index',compact('scroll'))->with('about',$about)->with('title',$title)- 
>with('menu',$menu);

view is code here :

@foreach($menu as $row)
   <li><a href="">{{$row->menu}}</a></li>
@endforeach

Upvotes: 0

Views: 42

Answers (1)

user5446912
user5446912

Reputation:

If i understand your problem, this is solved with basic HTML (Anchor) and adding the target (point on page) to your $menu-item.

@foreach($menu as $row)
    <a href="#{{ $row->targetId }}">{{ $row->menu }}</a>
@endforeach

Then add an element with the same id as $row->targetId:

<div id="ID-OF-TARGET-DIV">
    My text...
</div>

You can also use Str::slug() to create unique IDs from $row->menu, assuming all rows are unique.

@foreach($menu as $row)
    <a href="#{{ Str::slug($row->menu, '-') }}">{{ $row->menu }}</a>
@endforeach

You still have to add each id to an html element, how to do that depends on your full code.

See documentation for slug()

Upvotes: 1

Related Questions