如何在laravel5中的刀片文件中使用多个if语句

时间:2016-03-16 11:34:46

标签: php laravel-5

在laravel5中而不是使用foreach我可以使用if语句根据SQL查询过滤数据。如何在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

控制器:

  public function index()
    {

        $view=DB::table('property_details')

        ->get();
        return View::make('index', array('val'=>$view));        

     } 

     public function rentshow()
    {  
        $show=DB::table('property_details')
        ->where('sale_or_rent','=','rent')
        ->get();
        return View::make('index', array('val'=>$show));        

     }

     public function saleshow()
    {  
        $show=DB::table('property_details')
        ->where('sale_or_rent','=','sale')
        ->get();
        return View::make('index', array('val'=>$show));        

     }

1 个答案:

答案 0 :(得分:0)

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

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

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