Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pluck distinct relations in laravel?

Tags:

php

laravel

i need to pluck fromcity relation from Route. eg

 $list = Route::with('fromcity')->get()->pluck('fromcity')->toArray();

but it returns duplicate cities from relation. how to get distinct records? Thanks in Advance

like image 798
Neha Avatar asked Sep 03 '25 02:09

Neha


1 Answers

Try this

$list = Route::with('fromcity')->get()->pluck('fromcity')->unique()->toArray();

like image 94
Bruce Avatar answered Sep 05 '25 00:09

Bruce