$cities_for_select = City::lists('city', 'id');
I would do this for ONE record
//to return only 1 record
$city = DB::select("SELECT ...WHERE city_id = ?")->first();
return View::make('test',$city);
then you can access from the view...
$city->name
OR this for many records
// to return many records
$cities = DB::select("SELECT ...")->get();
return View::make('test',$cities );
and the view...
foreach($cities as $city)
{
$city->name;
}
use pmall's suggestion. That returns an array (id => city). Extjac's answer is a bit n00b.
Actually you could just change the "app/config/database.php" "fetch" attribute from "PDO::FETCH_CLASS" to "PDO::FETCH_ASSOC".
Or if you don't want this in all the application Config::set('database.fetch' PDO::FETCH_ASSOC); will do.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community