Home > front end >  Create anchor tag with route contain under @php script in blade template
Create anchor tag with route contain under @php script in blade template

Time:03-06

Route not working. how can I write an anchor tag, based on some condition? if the condition is true then the anchor tag will be printed with the route, I write the below code But I get an error.

In my blade template

@php
    if(SOMECONDATION){
    echo '<a href="{{ route('my.route') }}">Approve</a>';
    }   
@endphp

CodePudding user response:

{{ }} is echo-ing. You can use this :

@if($p->name == 0)
<a href="{{ route('my.route') }}">Approve</a>
@endif

CodePudding user response:

No need to use echo or anything. Directly use @if @endif and for route use {{ }}

    @if($condition)
     <a href="{{ route('something') }}">Approve</a>
   @endif
  • Related