Created
August 13, 2015 13:50
-
-
Save vs0uz4/836249d706edb05aab37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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