working with laravel 5.6 and mysql. I have following table name as vehicles
id name categoryname brandname model
1 juy car toyota 121
2 gty van nissan caravan
3 bgh car bmw 520d
4 hyu van ford max
5 nhj car toyota 121
6 gtr car toyota corolla
7 gtr van nissan caravan
i am using following controller function to display categorynames with bransnames
public function filterbrand ()
{
$vehicles = DB::table('vehicles')
->orderBy('categoryname', 'asc')
->get();
return view('vehicles.brand')->withVehicles($vehicles);
and use following blade file to show data
<?php $cat = ""; ?>
@foreach($vehicles->unique('brandname') as $vehicle)
@if($vehicle->categoryname != $cat )
<?php $cat = $vehicle->categoryname; ?>
<br><br>
@endif
<ul>
<li></li> <br>
</ul>
@endforeach
this is printing this types outputs
car
toyota
bmw
van
nissan
ford
but now I need print also modelnames with its counting like this
car
toyota
121 (2)
corolla (1)
bmw 520d (1)
van
nissan
carvan (2)
ford
max (1)
How can I modify my blade or controller for this new requirements?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire