The same posts shows to times - php

The problem here is that red marked news ARE THE SAME. And what I want to do here is to make sure that the new posts wont repeat themselves. Because now as you can see the same posts shows up two times before another is posted.
This is the code:
#extends('app')
#section('content')
<div class="row">
<div class="col-xs-12 col-sm-9">
#if(count($latest))
<div class="col-md-12">
<a href="/post/{{$latest->slug}}/{{$latest->id}}">
<img class="img-responsive" src="{!! url($latest->image) !!}" alt="" style="padding: 0px; height: 400px; width: 720px"></a>
<h2 class="post" style="margin-top: 0; color: #666">
#foreach($latest->category as $cat)
<a style="color: red; text-transform: uppercase; font-size: 13px" href="/categories/{{$cat->name}}">{{$cat->name}}</a>
#endforeach
<br>{!! strip_tags(link_to_action('PostsController#show', $latest->title, [$latest->slug, $latest->id])) !!}</h2>
<span style="color: #b8b8b8">Paskeblta {{$latest->created_at}}</span>
<hr>
</div>
#else
<p>Nėra naujienų</p>
#endif
<div class="row">
#foreach($posts as $post)
<div class="col-xs-6 col-lg-6">
<a href="/post/{{$post->slug}}/{{$post->id}}">
<img class="img-responsive" style="width: 352px; height: 180px" src="{!! url($post->image) !!}" alt=""></a>
<h3 class="post" style="font-size: 1.4em; margin-top: 0; color: #666"><small style="color: red; text-transform: uppercase; font-size: 11px">
#foreach($post->category as $cat)
{{$cat->name}}
#endforeach
</small><br>{{strip_tags($post->title)}}</h3>
<span style="color: #b8b8b8">Paskelbta {{$post->created_at}}</span>
<br><br>
</div><!--/.col-xs-6.col-lg-4-->
#endforeach
</div><!--/row-->
</div><!--/.col-xs-12.col-sm-9-->
#include('comp.sidebar')
</div><!--/row-->
<hr>
#stop

You could add a check in the loop: if the current post is the same as the featured one, ignore it.
#foreach($posts as $post)
#unless ($post == $latest)
// rest of html goes here
#endunless
#endforeach
If the objects aren't actually the same objects, just change the check accordingly - e.g. #unless ($post->id == $latest->id) or similar.

Related

Laravel/Bootstrap 5 - Making a card row shrinks its image

I'm using Bootstrap's 5 card and Laravel to make a car card. When I try to make a row with cards, the image shrinks. If I remove the "row" class, its image fits perfectly. ¿How can I solve this issue?
<h1>Vehículos</h1>
<div class="row">
#foreach ($autos as $auto)
<div class="card" style="width: 18rem; border-radius: 25px;">
<a href="{{ URL('auto/'.$auto->id)}}">
<img src="{{ URL('images/'.$auto->foto)}}" class="card-img-top" alt="..." style="border-top-right-radius: 25px; border-top-left-radius: 25px;">
</a>
<div class="card-body">
<h5 class="card-title">{{$auto->marca." ".$auto->modelo}}</h5>
<p class="card-text">
Año: {{$auto->año}}
Kilometros: {{$auto->kilometros}}
Motor: {{$auto->motor}}
Combustible: {{$auto->combustible}}
Precio: $ {{$auto->precio}}
</p>
</div>
</div>
#endforeach
</div>
</div> ```
[1]: https://i.stack.imgur.com/TviHn.png
I had to reproduce the error on my own end and I found the issue. When using a bootstrap row , you have to add columns using the col class. So change your code to this
<h1>Vehículos</h1>
<div class="row">
#foreach ($autos as $auto)
<div class="col">
<div class="card" style="width: 18rem; border-radius: 25px;">
<a href="{{ URL('auto/'.$auto->id)}}">
<img src="{{ URL('images/'.$auto->foto)}}" class="card-img-top" alt="..." style="border-top-right-radius: 25px; border-top-left-radius: 25px;">
</a>
<div class="card-body">
<h5 class="card-title">{{$auto->marca." ".$auto->modelo}}</h5>
<p class="card-text">
Año: {{$auto->año}}
Kilometros: {{$auto->kilometros}}
Motor: {{$auto->motor}}
Combustible: {{$auto->combustible}}
Precio: $ {{$auto->precio}}
</p>
</div>
</div>
</div>
#endforeach
</div>
</div>
This would fix the issue of the image being shrinked.
SIDENOTE: Do note that the bootstrap col class has prefixes to make it adapt to different screens. You can check out the docs for more info.

Bootstrap three columns with dynamicaly inserted image

This is what I want to achieve:
But this is the result I get:
The img and text are inserted from the DB. This is the code:
<div class="row" style="margin-top: 8rem;">
#foreach ($rooms as $room)
<div class="col-4" data-category="{{ $room->data_category}}">
<a href="#zoomImg{{ $room->id }}" data-bs-toggle="modal" data-bs-target="#zoomImg{{ $room->id }}">
<img src="{{ $room->img }}" alt="" class="img-fluid">
</a>
<div class="text-left mt-3 mb-5">
<p class="product-subtitle">{{ $room->name }}</p>
<h4 class="product-title">Shop the Look</h4>
<a class="product-price-link" href="#getPriceByRoom{{ $room->id }}" data-bs-toggle="modal" data-bs-target="#getPriceByRoom{{ $room->id }}">get price</a>
</div>
</div>
#endforeach
</div>
I tried positioning the #foreach in a different way and still could't get the result I wanted. Any suggestions?
Found a solution to the layout on this article
.masonry-container {
column-count: 3;
column-gap: 15px;
}
.masonry-item {
display: inline-block;
width: 100%;
}
.masonry-item img {
display:block;
width: 100%;
}

Laravel is passing another variable from blade

I have a script when I display all what is in collection, I use foreach. One of all collection you can delete clicking specific button, but the problem is you can click collection with ID 17 and it will delete first existing collection, even with id = 1. I do not know what to do because i think that everything looks ok. When I dump controller I see first existing collection id. I mean that moment -> ReviewAnswerController#destroy in code
Can you help me?
#foreach($data->reviewAnswers as $answer)
<div class="row">
<div class="col-md-12" style="position: inherit; display: flow-root; float: right; background: #94969f; margin-top: 15px; margin-right: 15px; padding: 5px; border-radius: 5px; width: 80%; color: white; padding-bottom: 3px;">
<div class="col-md-1">
<?php $avAnswer = App\Models\UserData::where('user_id', $data->sender_id)->first() ?>
#if(empty($avAnswer->avatar))
<img src="{{ asset('img/lock_thumb.jpg')}}" style="width: 50px; height: 50px; border: 2px solid white;border-radius: 50%;">
#else
<img src="{{ asset('/storage/uploads/avatars/'. $av->avatar) }}" style="width: 50px; height: 50px; border: 2px solid white;border-radius: 50%;">
#endif
</div>
<div class="col-md-5">
<div style="float: left;">
{{$answer->id}}
<b>{{$answer->sender_name}} {{$answer->sender_surname}}</b> |
#if($answer->sender_role_specific)
{{$answer->sender_club_role}} ({{$answer->sender_role_specific}})
#else
{{$answer->sender_club_role}}
#endif
</div>
</div>
<div class="col-md-5"></div>
<div class="col-md-1">
#if(Auth::user()->role == 'admin')
<form id="reviewAnswerForm" action="{{ action('ReviewAnswerController#destroy', $answer->id) }}" method="POST">
{{ method_field('DELETE') }} {{ csrf_field() }}
<button class="btn" style="background-color:transparent; float: right;">
<img src="{{ asset('img/review-icons/delete.png')}}" style="float: right;"/>
</button>
</form>
#endif
</div>
<div class="col-md-11" style="border-top: 1px solid; padding-bottom: 5px;">
<p>{{$answer->answer}}</p>
<button class="btn" style="background-color:transparent; float: right;" data-toggle="modal" data-target="#modalreportanswer">
<img src="{{ asset('img/review-icons/report.png')}}" style="width: 15px; height: 15px; float: right; margin-top: 10px;">
</button>
<div class="modal fade" id="modalreportanswer" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">#lang('main.report')</h4>
</div>
<div class="modal-body">
<form action="{{ action('ReviewAnswerReportController#store') }}" method="POST" class="">
{{ csrf_field() }}
<div class="form-group">
<label for="comment">#lang('main.reason'):</label>
<textarea id="text" class="form-control noresize" rows="5" name="reason"></textarea>
<h6 class="pull-right" id="count_message"></h6>
</div>
<div class="form-group">
<input type="hidden" class="form-control" value="{{ $answer->id }}" name="reviewAnswerId">
</div>
<button class="btn btn-primary" type="submit">#lang('main.report')!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endforeach
In your code you have 2 method, POST and DELETE in the same Form
<form id="reviewAnswerForm" action="{{ action('ReviewAnswerController#destroy', $answer->id) }}" method="POST">
{{ method_field('DELETE') }} {{ csrf_field() }}
Try with this , I use Laravel Collective , it is very clear.
Route::delete('answer/{id}', ['as' => 'reviewAnswer.destroy', 'uses' => 'ReviewAnswerController#destroy'] );
#if(Auth::user()->role == 'admin')
{!! Form::open(['method' => 'DELETE','route' => ['reviewAnswer.destroy',
$answer->id, ] ]) !!}
#endif

I want to switch to another page after clicking on the pic in codeigniter, how i can do it?

<div class="col-lg-4 col-sm-6">
<a href="#" class="portfolio-box">
<img src="img/portfolio/1.jpg" class="img-responsive" alt="">
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-category text-faded">
Category:-
</div>
<div class="project-name">
Mobile
</div>
</div>
</div>
</a>
</div>
//1.jpg image is appearing in the view i want to switch to another view after clicking on this image.
You can achieve this with css:
#my-div{
background-color: #000;
width: 200px;
height: 200px }
a.fill-div {
display: block;
height: 100%;
width: 100%;
text-decoration: none}
<div class="col-lg-4 col-sm-6" id="my-div">
the rest of it.
</div>

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. 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"><span>All</span></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">{{$value->city}}</h3>
<h4 class="property-box-subtitle">{{$value->state}}</h4>
<div class="property-box-picture">
<div class="property-box-price">{{$value->property_price}}</div>
<div class=""> <img src="images/test/{{$value->image}}" alt=""> </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">{{$value->city}}</h3>
<h4 class="property-box-subtitle">{{$value->state}}</h4>
<div class="property-box-picture">
<div class="property-box-price">{{$value->property_price}}</div>
<div class=""> <img src="images/test/{{$value->image}}" alt=""> </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">{{$value->city}}</h3>
<h4 class="property-box-subtitle">{{$value->state}}</h4>
<div class="property-box-picture">
<div class="property-box-price">{{$value->property_price}}</div>
<div class=""> <img src="images/test/{{$value->image}}" alt=""> </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.

Categories