Я столкнулся с некоторыми проблемами с моим selectbox, где я поставлю все доступные категории в
В моем контроллере я использую этот снимок:
return View::make("stories.add") ->with("title","Indsend novelle") ->with("categories", Category::all());
На мой взгляд, я пытаюсь поместить все категории в selectbox следующим образом:
{{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) { } } }
в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) { } } }
в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) { } } }