Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

towhid's avatar

Same Data show in foreach loop how to unique data show in blade ?

@foreach($religions as $religion)
@if($religion->value_id == $user->user_info->user_religion)
{{$religion->value_name}}
@endif
@endforeach

here is show three times show data

Here is  my data  table value 
column name 
valuename, value_id 
muslim => 1, 
buddhist => 2, 
hindu ] => 3;
muslim = > 1,
hindu => 3,

checking value_id show value name     , 

i need answer only muslim  when value id match 1 
0 likes
4 replies
towhid's avatar

No i just collect data from Database and data save as like my requirement - you just tell me - if any function laravel or any other process to show unique value ?

after googling i try this kind of function but not understand why not show output accurately.

unique(),
distinct()
pluck()
Nakov's avatar

Well you iterate over the religions and based on your table data you have duplicate value_id and value_name which means for each time it appears you will get the value_name printed out.

You can add a method in the model or this in your controller and get a single value instead:

$userReligion = Religion::where('value_id', $user->user_info->user_religion)->first();

pass that to the view and use it as $userReligion->value_name.

Or add this ugly bit in the view instead:

@foreach($religions->unique('value_id') as $religion)

Please or to participate in this conversation.