This is something in my getIndex() function in the controller
public function getIndex() {
$categories = Category::all();
foreach ($categories as $category) {
$categories[$category->id] = $category->name;
}
......
}
So I expected to get all the category names from the loop.
However, for example, if I want to get the result by doing this in the view
@foreach ($categories as $name)
<ul>
<li>{{var_dump($name)}}</li>
</ul>
@endforeach
The result is like
object(Category)#169 (20) { ["fillable":protected]=> array(1) { [0]=> string(4) "name" } ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(4) { ["id"]=> string(1) "1" ["name"]=> string(3) "foo1" ["created_at"]=> string(19) "2014-11-08 14:29:30" ["updated_at"]=> string(19) "2014-11-08 14:29:30" } ["original":protected]=> array(4) { ["id"]=> string(1) "1" ["name"]=> string(3) "foo1" ["created_at"]=> string(19) "2014-11-08 14:29:30" ["updated_at"]=> string(19) "2014-11-08 14:29:30" } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) }
string(3) "foo1"
- string(11) "foo2"
Where does the first result come from and how do I get rid of it? Thanks!