jeudi 26 avril 2018

Get all the cities of a state

I would like to list all the cities of a state.

Here an example of my table "properties"

+----+-------------+--------+--------+---------------+
| id | title       |price   | state  | city          |
+----+-------------+--------+--------+---------------+
| 1  | test        | 55     | Florida| Jacksonville  |
+----+-------------+--------+--------+---------------+
| 2  | test 2      | 30     | Nevada | Las Vegas     |
+----+-------------+--------+--------+---------------+
| 3  | test 3      | 200    | Florida| Miami         |
+----+-------------+--------+--------+---------------+

index.blage.php template:

    @foreach($all_cities as $city)
    <div class="col-lg-2">
        <a href="">  </a>
    </div>

    @endforeach

HomeController.php

   public function home()
    {

        $all_cities = Property::select("city")->groupBy('city')->get();
        return view('index', ['all_cities' => $all_cities]);

    }

For example get all cities of Florida.

Any help would be appreciated

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire