I am trying to get unique values in a drop down list. Code for drop down is:
@foreach($admin_bills as $admin_bill)
<?php $month = date('M, Y', strtotime($admin_bill->created_at)); ?>
<option value="{{ $admin_bill->id }}">{{ $month }}</option>
@endforeach
This gives me all the values based on created_at
. For example, if there are multiple entries on same month, it gives me results like
Aug, 2017
Aug, 2017
Aug, 2017
Sep, 2017
Sep, 2017
But if there are multiple entries on same month, I want them to show once in the drop down. So the result will be like:
Aug, 2017
Sep, 2017
I cannot simply use function like array_unique()
here and the $admin_bill->id
should get the first id of unique $month
. How can I do that? Please help. I am using Laravel 5.4
Thank you.