I use this code to display certain users per record in multiple property name. Though I wanted to display 1 name instead of multiple including their IDs.
@foreach( $records as $record )
@if( $record->investment_type == null )
<tr>
<td>{{ $record->client_id }}</td>
<td>{{ $record->firstname }} {{ $record->lastname }}</td>
<td>{{ $record->name }}</td>
<td class="details-control"></td>
</tr>
@endif
@endforeach
Here's the output of my current code.
While this is what i wanted to be looked like.
I tried, array_unique
but the output gives me error
Source code came from this: php Removes duplicate values in foreach and just followed what was solved the issue from the poster. But it don't work on my end.
Many thanks for your help.
UPDATE:
Here's the output of the $records
from var_dump
.
And this is the code inside controller.
$records = DB::table('assets')
->join('client', 'client.Id', '=', 'assets.client_id')
->join('property', 'property.Id', '=', 'assets.property_id')
->select('assets.client_id','client.firstname','client.lastname','property.name','assets.investment_type')
->orderBy('assets.client_id')
->get();
Not much familiar in laravel syntax. You can just convert it if you want. Anyway, to do this you need to check the previous value. I assume that this is sorted by name.
First create a previous variable
Here is the code where we check if it is the same in the previous value
At the end of loop just add the current value in previous value variable
Whole Code