skip to Main Content

Anyone who experience this issue with anchor tags at laravel , I encounter an issue which href shows correct url href="job but the properties value shows = jobs/jobs. I don’t have any issue with this anchor tags when I’m in different routes.

I used this route

Route::get('/jobs/{id}', function ($id)  {
    $job = Job::find($id);
    return view('job',['job'=>$job]);
});

enter image description here

enter image description here

I try to look for any similar issue here but I found nothing. the anchor tag is reusable , I did used a static anchor tag but both shows values /jobs/jobs but the href is /jobs only

@props([‘active’ => false])

<a  class="{{ $active ? 'bg-gray-900 text-white' : 'text-gray-300 hover:bg-gray-700 hover:text-white' }} rounded-md px-3 py-2 text-sm font-medium" 
aria-current="{{ $active ? 'page' : 'false' }}"
{{ $attributes }}
>{{$slot}} </a>

2

Answers


  1. Chosen as BEST ANSWER

    I don't know if this is how you solved this but I try to changed the href=""

    to {{ url(name_path) }}


  2. If you’re using a reusable Blade component for your anchor tags, ensure that the href attribute is being set correctly.

    @props(['active' => false, 'href'])
    
    <a href="{{ $href }}" class="{{ $active ? 'bg-gray-900 text-white' : 'text-gray-300 hover:bg-gray-700 hover:text-white' }} rounded-md px-3 py-2 text-sm font-medium" aria-current="{{ $active ? 'page' : 'false' }}">
    {{ $slot }}
    </a>
    

    Or Add some debugging statements to check the values being passed to your Blade component.
    {{– Debugging –}}

    <pre>{{ $href }}</pre>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search