Gaurav Singh
Gaurav Singh

Reputation: 39

On every click link changes in blade view

This is the blade view to create the url links

@section ('category')
    <ul class="main-categories">
        @foreach($category as $category)
            <li class="main-nav-list"><a href="{{asset('/glassfilm')}}/{{$category->category}}">{{ $category->category }}<span class="number">{{ $category->count}}</span></a></li>
        @endforeach
    </ul>
@endsection

when i click for the first time it's working fine and the url I get is

http://localhost/shopnew/public/glassfilm/Frosted

when I click for the secon time the url I get is

http://localhost/shopnew/public/glassfilm/glassfilm/Frosted

what I am doing wrong?

Upvotes: 1

Views: 376

Answers (2)

Amit Senjaliya
Amit Senjaliya

Reputation: 2945

asset() method is used to include CSS/JavaScript/images files.

url() method used to generate a URL to a link.

Laravel's route() method is very helpful. So you can try:

<li class="main-nav-list"><a href="{{ route('glassfilm-category', ['name' => $category->category]) }}">{{ $category->category }}<span class="number">{{ $category->count}}</span></a></li>

@section ('category')
    <ul class="main-categories">
         @foreach($category as $category)
             <li class="main-nav-list"><a href="{{ route('glassfilm-category', $category->category) }}">{{ $category->category }}<span class="number">{{ $category->count}}</span></a></li>
         @endforeach
    </ul>
@endsection

Upvotes: 2

Yasin Patel
Yasin Patel

Reputation: 5731

Change your route as below :

@section ('category')
  <li class="main-nav-list">
    <a href="{{ route('glassfilm-category',['name' => $category->category]) }}"> {{ $category->category }}
      <span class="number">{{ $category->count}}</span>
    </a>
  </li>
@endsection

Upvotes: 2

Related Questions