php - remove the duplicate entry for the value in laravel view file
Get the solution ↓↓↓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 )
)
Answer
Solution:
In controller
$unique = $am_detials->unique();
Then u give unique data. Check the documenting https://laravel.com/docs/master/collections#method-unique
Answer
Solution:
You should set yourgeography
field as unique in your migration.
$table->string('geography')->unique();
Answer
Solution:
TrygroupBy()
in your controller.
For example:
$am_details = Model::groupBy('geo')->get();
It will group all the duplicates
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: installation failed, reverting ./composer.json and ./composer.lock to their original content.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.