Skip to content

Instantly share code, notes, and snippets.

@vs0uz4
Created August 13, 2015 13:50
Show Gist options
  • Save vs0uz4/836249d706edb05aab37 to your computer and use it in GitHub Desktop.
Save vs0uz4/836249d706edb05aab37 to your computer and use it in GitHub Desktop.
// Wraper para o método lists
public function lists($field, $key)
{
return Model::lists($field, $key);
}
// Podendo concatenar o array com um valor nulo (null) para criar a opção no select
// algo tipo: "Selecione um valor"
public function lists($field, $key, $selectText = null)
{
$options = Model::lists($field, $key);
if (isset($selectText)
return [null => $selectText] + $options;
return $options;
}
// Podendo também retornar
public function categoriesForSelect()
{
$categories = Category::all()->lists("value", "id");
return $categories;
}
// Na documentação http://laravel.com/docs/5.1/queries
You may also specify a custom key column for the returned array:
$roles = DB::table('roles')->lists('title', 'name');
foreach ($roles as $name => $title) {
echo $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment