Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

littledaggers's avatar

Bootstrap badge display only when a condition is met

I want to display a badge by removing the hidden attribute when a certain condition is met. This condition is when 1 or more of 3 data queries have entries that meet the query conditions.

the badge code is as follows:

</div>
<span class="position-absolute top-0 start-100 translate-middle p-2 bg-danger border border-light rounded-circle badge badge-pill badge-danger" id="new-notification" hidden>
<span class="visually-hidden">New alerts</span>
</span>
</div>

I want to display it by removing the hidden attribute when these queries in the controller have entries that meet the conditions:

$quot_one = ClientQuotation::where('verified_receipt', '0')->whereDate('created_at', '=', Carbon::yesterday())->get();
$quot_seven = ClientQuotation::where('validated_7', '0')->whereDate('created_at', '=', Carbon::today()->subDays(7))->get();
$follow_today = QuotationFollowup::whereDate('date', '=', Carbon::today())->where('done', '0')->get();

I cannot think of a way to do it. Since the conditions are server side and the badge is client side. This is an issue I am facing as entry level web developer. Could anyone give me some insight on how to approach this situation? Thank you in advance

0 likes
8 replies
martinbean's avatar
Level 80

@littledaggers It would probably be better just to show the badge only if your conditions are met:

@if($conditionsAreMet)
    <!-- New alerts badge mark-up here -->
@endif
1 like
littledaggers's avatar

@martinbean what I mean by my question is, can the $conditonsAreMet have the query conditions written in the blade file under @if ? like for example can it work if I write:

@if($quot_one = ClientQuotation::where('verified_receipt', '0')->whereDate('created_at', '=', Carbon::yesterday())->get();)
    <!-- New alerts badge mark-up here -->
@endif
littledaggers's avatar

I will refer to the laravel documentation relating to queries in order to try and understand what I can do in this matter

martinbean's avatar

@littledaggers You don’t want to be doing queries in views. You should be passing the data the view needs to the view from a controller.

1 like
littledaggers's avatar

@martinbean noted, thank you for your advice, and sorry that my questions are a bit vague, I'm just very new to coding

Please or to participate in this conversation.