Reputation: 7175
I have the response from the data as $am_details and I want to get the unique geo value in sect box dropdown in view files I have tries as
<select name="geo" class="ui fluid dropdown" id="geo" multiple="" >
@foreach($am_details as $summary)
<option value="{{$summary->Geography}}">{{$summary->Geography}}</option>
@endforeach
</select>
But displaying with duplicate geo value I want to remove the duplicate entry in laravel view selectbx option.
$am_details
response in as below
Array ( [0] => stdClass Object ( [AccountManager] => jigar.lohia [CustomerCode] => UAE_0068 [Geography] => ME )
[1] => stdClass Object ( [AccountManager] => jigar.lohia [CustomerCode] => UAE_0068 [Geography] => ME )
[2] => stdClass Object ( [AccountManager] => jigar.lohia [CustomerCode] => UAE_0068 [Geography] => ME )
)
Upvotes: 1
Views: 236
Reputation: 244
Try groupBy()
in your controller.
For example:
$am_details = Model::groupBy('geo')->get();
It will group all the duplicates
Upvotes: 1
Reputation: 69
You should set your geography
field as unique in your migration.
$table->string('geography')->unique();
Upvotes: 2
Reputation: 306
In controller
$unique = $am_detials->unique();
Then u give unique data. Check the documenting https://laravel.com/docs/master/collections#method-unique
Upvotes: 2