Div different depending on the date Hi, let's say I have a big div in which I put all the elements that have today's date but I would like to create another card if it's a different date and put all the data there.
Look how I have
@foreach($nsf->groupBy('project_name') as $group)
@if($county->name == $group->first()->county)
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 dashboard-elements-list">
<div class="col-xl-12 col-lg-12 col-md-12 col-12">
<div class="row">
<div class="col-xl-9 col-lg-9 col-md-9 col-sm-12 col-12 mt-2">
<div class="pp-model-item">
How can I put an if based on the date? Like if he has today's date to display a card, for another time another card
I thought of something like that but it doesn't work, because I still have an if
Carbon\Carbon::today()->format('Y-m-d') != Carbon\Carbon::parse($group->created_at)->format('Y-m-d')
@kijdsa nothing wrong with using another if
@foreach($nsf->groupBy('project_name') as $group)
@if($county->name == $group->first()->county)
@if(Carbon\Carbon::today()->format('Y-m-d') != Carbon\Carbon::parse($group->created_at)->format('Y-m-d'))
// do something
@else
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 dashboard-elements-list">
<div class="col-xl-12 col-lg-12 col-md-12 col-12">
<div class="row">
<div class="col-xl-9 col-lg-9 col-md-9 col-sm-12 col-12 mt-2">
<div class="pp-model-item">
syntax error, unexpected 'endforeach' (T_ENDFOREACH), expecting elseif (T_ELSEIF) or else (T_ELSE)
When i try with if
@kijdsa this approach uses elseif instead of nested if.
@if($county->name == $group->first()->county && Carbon\Carbon::today()->format('Y-m-d') != Carbon\Carbon::parse($group->created_at)->format('Y-m-d')
)
// do something
@elseif ($county->name == $group->first()->county && Carbon\Carbon::today()->format('Y-m-d') == Carbon\Carbon::parse($group->created_at)->format('Y-m-d'))
// do something else
@else
// default behavior
@endif;
if add 'created_at' to $dates array in your Group model, then you can use
$group->created_at->format('Y-m-d')
instead of
Carbon\Carbon::parse($group->created_at)->format('Y-m-d')
@foreach($newsfeed->groupBy('project_name') as $group)
@if($county->name == $group->first()->county && Carbon\Carbon::today()->format('Y-m-d') == Carbon\Carbon::parse($group->created_at)->format('Y-m-d'))
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 dashboard-elements-list">
<div class="col-xl-12 col-lg-12 col-md-12 col-12">
<div class="row">
<div class="col-xl-9 col-lg-9 col-md-9 col-sm-12 col-12 mt-2">
<div class="pp-model-item">
<h4 align="center"><strong>{{ $group->first()->project_name }}</strong></h4>
<div class="pp-model-info-strip d-flex justify-content-center">
<i class="fad fa-map-marker-alt" style="color: #00c851;"></i>
<p>{{ $group->first()->county }} / {{ $group->first()->city }} / {{ $group->first()->zone }}</p>
</div>
<div class="pp-model-info-strip d-flex justify-content-center">
<h6>Cod proiect:w{{ $group->first()->project_wcode }}</h6>
</div>
<div class="pp-model-item-content pp-length-flex">
<div class="pp-model-picture pp-length-picture"></div>
<br />
<div class="pp-model-info pp-length-info">
@foreach ($group as $ns) @if($ns->model_type)
<div class="pp-model-info-strip">
<h6>{{ $ns->project_name }}</h6>
</div>
<div class="pp-model-info-strip">
<span>{{ $ns->content }}</span>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@elseif($county->name == $group->first()->county && Carbon\Carbon::today()->format('Y-m-d') != Carbon\Carbon::parse($group->created_at)->format('Y-m-d'))
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 dashboard-elements-list">
<div class="col-xl-12 col-lg-12 col-md-12 col-12">
<div class="row">
<div class="col-xl-9 col-lg-9 col-md-9 col-sm-12 col-12 mt-2">
<div class="pp-model-item">
<h4 align="center"><strong>{{ $group->first()->project_name }}</strong></h4>
<div class="pp-model-info-strip d-flex justify-content-center">
<i class="fad fa-map-marker-alt" style="color: #00c851;"></i>
<p>{{ $group->first()->county }} / {{ $group->first()->city }} / {{ $group->first()->zone }}</p>
</div>
<div class="pp-model-info-strip d-flex justify-content-center">
<h6>Cod proiect:w{{ $group->first()->project_wcode }}</h6>
</div>
<div class="pp-model-item-content pp-length-flex">
<div class="pp-model-picture pp-length-picture"></div>
<br />
<div class="pp-model-info pp-length-info">
@foreach ($group as $ns) @if($ns->model_type)
<div class="pp-model-info-strip">
<h6>{{ $ns->project_name }}</h6>
</div>
<div class="pp-model-info-strip">
<span>{{ $ns->content }}</span>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endif @endforeach
Property [created_at] does not exist on this collection instance. problem is this now
@kijdsa have you got
$table->timestamps();
in your groups migration?
@kijdsa grand.
if that's working,
with a bit of rework we can do
$group->created_at->isSameDay(Carbon::now());
instead of
Carbon\Carbon::today()->format('Y-m-d') == Carbon\Carbon::parse($group->created_at)->format('Y-m-d')
Please sign in or create an account to participate in this conversation.