Support the ongoing development of Laravel.io →
Views Blade Forms
Last updated 1 year ago.
0
$cities_for_select = City::lists('city', 'id');
Last updated 1 year ago.
0

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; 
}
Last updated 1 year ago.
0

use pmall's suggestion. That returns an array (id => city). Extjac's answer is a bit n00b.

Last updated 1 year ago.
0

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.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Sharping sharping Joined 28 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.