dimanche 9 décembre 2018

How to print count and print numbers of modelname in Laravel 5.6?

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('modelname') 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
121
toyota
corolla
bmw
520d


van
nissan
carvan
ford
max

but now I need print also modelnames with its counting like this


car
toyota
121(2)
toyota
corolla(1)
bmw
520d(1)


van
nissan
carvan(1)
ford
max(1)

how can I do this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire