選択ボックスでいくつかの問題に直面しています。使用可能なすべてのカテゴリを
私のコントローラーでは、このスニップを使用しています:
return View::make("stories.add")
->with("title","Indsend novelle")
->with("categories", Category::all());
私の見解では、これを使用してすべてのカテゴリを選択ボックスに入れようとしています:
{{Form::select("category", $categories)}}
私はこれを作ることができますが、Form::select は配列でなければならないので、うまくいきませんか?
@foreach ( $categories as $category )
{{$category->name}}
@endforeach
何をすべきか?
私はこれを作って動作しますが、見栄えが悪く、ユーザーフレンドリーではありません。何か提案はありますか?
$test = Category::all(); $myArray = array();
foreach ( $test as $o):
$myArray[] = $o->name;
endforeach;
return View::make("stories.add")
->with("title","Indsend novelle")
->with("categories", $myArray);
var_dump:
array(2) {
[0]=>
object(Category)#36 (5) {
["attributes"]=>
array(4) {
["id"]=>
string(1) "1"
["name"]=>
string(12) "Alderforskel"
["created_at"]=>
string(19) "0000-00-00 00:00:00"
["updated_at"]=>
string(19) "0000-00-00 00:00:00"
}
["original"]=>
array(4) {
["id"]=>
string(1) "1"
["name"]=>
string(12) "Alderforskel"
["created_at"]=>
string(19) "0000-00-00 00:00:00"
["updated_at"]=>
string(19) "0000-00-00 00:00:00"
}
["relationships"]=>
array(0) {
}
["exists"]=>
bool(true)
["includes"]=>
array(0) {
}
}
[1]=>
object(Category)#39 (5) {
["attributes"]=>
array(4) {
["id"]=>
string(1) "2"
["name"]=>
string(7) "Bondage"
["created_at"]=>
string(19) "0000-00-00 00:00:00"
["updated_at"]=>
string(19) "0000-00-00 00:00:00"
}
["original"]=>
array(4) {
["id"]=>
string(1) "2"
["name"]=>
string(7) "Bondage"
["created_at"]=>
string(19) "0000-00-00 00:00:00"
["updated_at"]=>
string(19) "0000-00-00 00:00:00"
}
["relationships"]=>
array(0) {
}
["exists"]=>
bool(true)
["includes"]=>
array(0) {
}
}
}