I have data like this :
TSAB001001 TSAB001002 TSAB001003 TSAB002001 TSAB002002 TSAB002003 TSIB001001 TSIB001002 TSIB001003 TSIB002001 TSIB002002 TSIB002003
I want to display it in blade :
- TSA
- BOO1
- TSAB001001
- TSAB001002
- TSAB001003 Count: 3
- B002
- TSAB002001
- TSAB002002
- TSAB002003 Count: 3
- BOO1
- TSI
- BOO1
- TSIB001001
- TSIB001002
- TSIB001003 Count: 3
- B002
- TSIB002001
- TSIB002002
- TSIB002003 Count: 3
- BOO1
Can you please help me how to imlementation this in laravel controller and view ?
You can use Laravel's Collection
map
andgroupBy
methods. First, we need to process the data so that we have a clear data structure to work with:Then we can use some nested loop to output the data:
We can use special
$loop
variable inside a blade loop to do some helpful things, like checking if it was the last item ($loop->last
).Learn more from the official docs: