Php 如何在laravel5中的blade文件中使用多个if语句

Php 如何在laravel5中的blade文件中使用多个if语句,php,laravel-5,Php,Laravel 5,在laravel5中,我可以使用if语句根据SQL查询过滤数据,而不是使用foreach。如何使用laravel5中的ifelse语句查看我的页面?在这些类中我有三个div类如何从数据库中获取数据?如何在blade.php文件中使用 如何使用路由和控制器从数据库中筛选数据 <div class="container"> <div class="block-content block-content-small-padding"> <div class="block-

在laravel5中,我可以使用if语句根据SQL查询过滤数据,而不是使用
foreach
。如何使用laravel5中的
ifelse
语句查看我的页面?在这些类中我有三个
div
类如何从数据库中获取数据?如何在blade.php文件中使用

如何使用路由和控制器从数据库中筛选数据

<div class="container">
<div class="block-content block-content-small-padding">
<div class="block-content-inner">
<h2 class="center">Recent Properties</h2>
<ul class="properties-filter">
  <li class="selected"><a href="#"  class="all" data-filter="*"><span>All</span></a></li>
  <li><a href="#"  class="featured"    data-filter=".featured" ><span>Featured</span></a></li>
  <li><a href="#" class="rent" data-filter=".rent" ><span>Rent</span></a></li>
  <li><a href="#"class="sale" data-filter=".sale" ><span>Sale</span></a></li>
</ul>
<div class="properties-items isotope"  style="position: relative; overflow: hidden; height: 810px;">
<div class="row ">
@if($val -> $value)
<div class="property-item col-sm-6 col-md-3 isotope-item my " style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
  <div class="property-box">
    <div class="property-box-inner">
      <h3 class="property-box-title"><a href="#">{{$value->city}}</a></h3>
      <h4 class="property-box-subtitle"><a href="#">{{$value->state}}</a></h4>
      <div class="property-box-picture">
        <div class="property-box-price">{{$value->property_price}}</div>
        <div class=""> <a href="#" class="property-box-picture-target"> <img src="images/test/{{$value->image}}" alt=""> </a> </div>
      </div>
    </div>
  </div>
</div>
@elseif($val -> $value)
<div class="property-item  col-sm-6 col-md-3 isotope-item"  style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
  <div class="property-box">
    <div class="property-box-inner">
      <h3 class="property-box-title"><a href="#">{{$value->city}}</a></h3>
      <h4 class="property-box-subtitle"><a href="#">{{$value->state}}</a></h4>
      <div class="property-box-picture">
        <div class="property-box-price">{{$value->property_price}}</div>
        <div class=""> <a href="#" class="property-box-picture-target"> <img src="images/test/{{$value->image}}" alt=""> </a> </div>
      </div>
    </div>
  </div>
</div>
@else($val -> $value)
<div class="property-item property-sale   col-sm-6 col-md-3 isotope-item myButton my"  style="position: absolute; left: 0px; top: 0px; transform: translate3d(0px, 0px, 0px);">
  <div class="property-box">
    <div class="property-box-inner">
      <h3 class="property-box-title"><a href="#">{{$value->city}}</a></h3>
      <h4 class="property-box-subtitle"><a href="#">{{$value->state}}</a></h4>
      <div class="property-box-picture">
        <div class="property-box-price">{{$value->property_price}}</div>
        <div class=""> <a href="#" class="property-box-picture-target"> <img src="images/test/{{$value->image}}" alt=""> </a> </div>
      </div>
    </div>
  </div>
</div>
@endif

您需要将
if
/
else
语句更正为:

@if ( $val == "something" )
  // do something
@elseif ( $val == "something-else" )
  // do something else
@else
  // the default
@endif

您不能像在代码中那样将条件传递给
@else

Multiple if语句在blade中与普通php没有什么不同。当前您的if语句不正确。您应该使用控制器过滤数据并将其传递给视图。你没有发布任何控制器,所以不清楚你想要实现什么。我同意@CanCelik。请发布您的控制器代码。让我解释一下,我的主页上有一个过滤器,带有四个锚定标签,如All | Featured | Rent | Sale。现在我正在尝试从数据库中筛选数据,当用户单击Rent时,如果单击All,则只会出现与租金相关的数据,然后所有数据都会出现,请记住我已经存储了这些值(Featured,Sale,Rent)在我的数据库列中。静态Html过滤器工作正常。
@if ( $val == "something" )
  // do something
@elseif ( $val == "something-else" )
  // do something else
@else
  // the default
@endif