-2

This is my code:

@foreach($category as $cat)
    <li><a href="{{ url('home/category',$cat->id) }}">{{ $cat->category_name }}</a></li>
@endforeach

When I click in URL it shows the page and my URL is: http://localhost/onlinenews/public/home/category/2

But after again I click other categories then my URL is: http://localhost/onlinenews/public/home/category/home/categorylist/3

How to fix this issue?

rap-2-h
  • 30,204
  • 37
  • 167
  • 263

2 Answers2

2

You should add a / at the beginning of your URL:

@foreach($category as $cat)
    <li><a href="{{ url('/home/category',$cat->id) }}">{{ $cat->category_name }}</a></li>
@endforeach
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
  • yes i added but it's not work it's shows like this again http://localhost/onlinenews/public/home/category/home/categorylist/home/categorylist/18 – user2659828 Jun 02 '16 at 11:19
  • @rap-2-h, your solution will not help, because OP has wrong web server configuration. Also, you do not need to add `/`, because `url()` helper never builds relative paths. – Alexey Mezenin Jun 02 '16 at 11:39
1

You're using wrong configuration. When you're building Laravel app, you should point you web server to a public directory which is in Laravel app root.

After doing that restart web server and your code will work fine.

Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279