user3386779
user3386779

Reputation: 7175

remove the duplicate entry for the value in laravel view file

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

Answers (3)

daffaquraisy
daffaquraisy

Reputation: 244

Try groupBy() in your controller. For example:

$am_details = Model::groupBy('geo')->get();

It will group all the duplicates

Upvotes: 1

Khurshid Yakubov
Khurshid Yakubov

Reputation: 69

You should set your geography field as unique in your migration.

$table->string('geography')->unique();

Upvotes: 2

Arjun bhati
Arjun bhati

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

Related Questions