Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

manojvarma's avatar

Writing a URL in if statement

Hi i am stuck in writing the URL inside of "if" statement. Here is my code. i want to know how to make it proper.

                        <a href="{{ url('samratbasic') }}"Go>
                        @else($device->name == 'RAKSHAK')
                        <a href="{{ url('rakshakbasic') }}"Go>
                        @endif
0 likes
9 replies
manojvarma's avatar

I tried but i am getting the following error Parse error: syntax error, unexpected ''): ?>' (T_CONSTANT_ENCAPSED_STRING) (View: /home/manoj/vinfinet/stock/resources/views/pages/basictest.blade.php)

InaniELHoussain's avatar

I guess the error isn't in that part, would you show us the full code?

manojvarma's avatar

Here is my full code


@section('content')

<!-- page content -->
        <div class="right_col" role="main">
          <div class="">
          

            <div class="clearfix"></div>

            <div class="row">
              
              
              
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Stock <small>Basic test</small></h2>
                    
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <p class="text-muted font-13 m-b-30">
                      </p>
                    <table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                      <thead>
                        <tr>
                          <th>Serial No</th>
                          <th>OP No</th>
                          <th>Device</th>
                          <th>State</th>
                          <th>Basic Test</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr>
                          @foreach($devices as $device)
                        <tr>
                        <td>{{ $device->slno}}</td>
                        <td>{{ $device->opno}}</td>
                        <td>{{ $device->name}}</td>
                        <td>@if($device->state == 0)
                                New 
                              @elseif ($device->state == 1)
                                Field-return
                              @endif </td>
                        <td>@if($device->name ==='SAMRAT'')
                        <a href="{{ url('samratbasic') }}"Go>
                        @else($device->name === 'RAKSHAK')
                        <a href="{{ url('rakshakbasic') }}"Go>
                        @endif
                        </td>
                        </tr>
                        @endforeach
                        </tr>
                         
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
        @endsection
Repox's avatar

You have a double single quote in the end of this conditional:

  <td>@if($device->name ==='SAMRAT'')
1 like
tam1's avatar

Maybe you don't need the if statement

<a href="{{ url(strtolower($device->name) . 'basic') }}">Go</a>

Please or to participate in this conversation.