In laravel5 instead of using foreach
I can use the if statement to filter the data on the basis of SQL query. How can I view my page using ifelse
statement in laravel5? I have three div
class in these class how to fetch the data from the database? How to use in the blade.php file?
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 ( $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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.