search

Home  >  Q&A  >  body text

Laravel: How to write href attribute based on if-else condition?

<p>我需要在 if-else 子句中通过 URL 检查“perPage=100”和“perPage=50”。</p> <pre class="brush:php;toolbar:false;">@if(perPage=100) <a class="btn btn-default btn-sm ajax-link back-btn" href="invoice-list?perPage=100" type="button" >Back to List</a> @elseif(perPage=50) <a class="btn btn-default btn-sm ajax-link back-btn" href="invoice-list?perPage=50" type="button" >Back to List</a> @else <a class="btn btn-default btn-sm ajax-link back-btn" href="invoice-list?perPage=10" type="button" >Back to List</a> @endif</pre></p>
P粉852578075P粉852578075458 days ago461

reply all(1)I'll reply

  • P粉289775043

    P粉2897750432023-09-01 11:26:23

    You can only write this line without any if:

    <a class="btn btn-default btn-sm ajax-link back-btn" href="{{url('invoice-list?perPage=' . $perPage)}}" type="button">Back to List</a>

    Make sure you have the $perPage variable

    reply
    0
  • Cancelreply