[英]how to use multiple if statement in blade file in laravel5
In laravel5 instead of using foreach
I can use the if statement to filter the data on the basis of SQL query. 在laravel5中,我可以使用if语句基于SQL查询来过滤数据,而不是使用foreach
。 How can I view my page using ifelse
statement in laravel5? 如何在laravel5中使用ifelse
语句查看页面? I have three div
class in these class how to fetch the data from the database? 我有三个div
类,这些类中如何从数据库中获取数据? How to use in the blade.php file? 如何在blade.php文件中使用?
How can I filter the data from database using routes and controller? 如何使用路由和控制器从数据库中过滤数据?
<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
Controller: 控制器:
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));
}
You need to correct your if
/ else
statements to: 您需要将if
/ else
语句更正为:
@if ( $val == "something" )
// do something
@elseif ( $val == "something-else" )
// do something else
@else
// the default
@endif
You can't pass a condition to @else
like you've done in your code. 您不能像在代码中那样将条件传递给@else
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.