First and foremost, i'm very green in Laravel. So pls take that into consideration if i use any wrong terminlogy or dont grasp some stuff that should be obvious to you all. I'm trying to populate a dropdown list with the results of database query.
Model for Dropdown Entries:
Class Dropdown {
public static function getFilters() {
$filter = DB::select(DB::raw('SELECT DISTINCT filter AS filt
FROM filter.database'));
return $filter;
}
}
Controller:
class FilterController extends BaseController {
public function getSql_Test() {
$dropdown = Dropdown::getFilters();
return View::make('Dropdown.show', ['Dropdown' =>$dropdown]);
}
}
What my controller accomplishes right now is to display the results of the query (which i want to populate the dropdown) on the page. Can someone pls help me on how to pass this entries onto the select tag here and show it on my View?
Documentation for dropdown is provided @ http://laravel.com/docs/4.2/html#drop-down-lists
You are already passing the data to the view. In your view/blade file, you can do something like this
Form::select('name', $Dropdown );
The problem with this is that, the select parameter expects a string. What i'll be passing on to it as per your suggestion will be an object.
Nope. Select statement accepts array as second argument. Since query builder returns the value as object, you have to remap to array before passing it select.
$filter = DB::select(DB::raw('SELECT DISTINCT filter AS filt FROM filter.database'));
foreach ($filter as $key => $value) {
$dropdown[$key] = $value->filt;
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community