php if else条件在刀片文件(laravel 5.3)

jtw3ybtb  于 2023-05-27  发布在  PHP
关注(0)|答案(5)|浏览(162)

我想在我的刀片文件中检查if/else条件。我想检查条件$user->status =='waiting',如下面给出的代码。输出如我预期的那样正确返回。但是沿着我的输出中,我发现打印了花括号{}。我想删除结果中的花括号。我的if条件有什么问题吗?

@if($user->status =='waiting')
         {
           <td><a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{{ $user->travel_id }}" data-toggle="modal" data-target="#myModal">Approve/Reject<a></td>
         }
         @else{
           <td>{{ $user->status }}</td>
         }
         @endif
kxe2p93d

kxe2p93d1#

不需要花括号你可以直接写

@if($user->status =='waiting')         
      <td><a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{{ $user->travel_id }}" data-toggle="modal" data-target="#myModal">Approve/Reject<a></td>         
@else
      <td>{{ $user->status }}</td>        
@endif
ubby3x7f

ubby3x7f2#

我认为你放了太多的花括号。试试这个

@if($user->status=='waiting')
            <td><a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{!! $user->travel_id !!}" data-toggle="modal" data-target="#myModal">Approve/Reject</a> </td>
            @else
            <td>{!! $user->status !!}</td>
        @endif
wh6knrhe

wh6knrhe3#

你不必在blade条件中使用大括号,所以你的代码应该是这样的:

@if($user->status =='waiting')
    <td>
        <a href="#" class="viewPopLink btn btn-default1" role="button" data-id="{{ $user->travel_id }}" data-toggle="modal" data-target="#myModal">
            Approve/Reject
        <a>
    </td>
@else
    <td>
        {{ $user->status }}
    </td>
@endif
cgvd09ve

cgvd09ve4#

如果要赋值,则根据刀片内的其他值.

@if($shipping_fee >= 1)
  @php
    $shipping_fee = $any_variable1
  @endphp
@else
  @php
    $shipping_fee = $any_variable2
  @endphp
@endif
ua4mk5z4

ua4mk5z45#

你可以这样写

@php

  $msg = "";

  if(condition)

  $msg = "some text";

  elseif(condition)

  $msg = "some text";

  @endphp

相关问题