php - Populating dropdown using Laravel Eloquent and DB -
i'm on laravel , eloquent, , trying populate view's dropdown box results of select query.
in controller:
public function uploaddocs($userid) { $doc_options = db::select('select document.document_description document user_id = ?', array($userid)); return view::make('uploaddocs')->with('doc_options', $doc_options); }
in view:
<body> {{ form::select('doc_options_id', $doc_options) }} </body>
i'm getting following stack trace:
htmlentities() expects parameter 1 string, object given (view: /home/vagrant/code/eduview/app/views/uploaddocs.blade.php)
any ideas? thanks.
try
$doc_options = db::statement(db::raw('select document.document_description document user_id = ?', array($userid)))->get();
edit: should explain first.
db::select()
used database builder in order chain onto other chain-able functions, , not doing whole query.
you use db::statement
provide new custom sql query in it, have specify contents of statement()'s parameter raw query. hence db::raw
alternatively take advantage of eloquent or laravel's query builder creating eloquent model called document
in app/models
contents as:
class document extends eloquent {}
and swap out query above with:
$doc_options = document::select('document_description')->where('user_id','=',$userid)->get()
Comments
Post a Comment