【发布时间】:2015-07-02 18:52:37
【问题描述】:
我有 Post 和 Category 模型。当我创建一个新帖子时,我想将现有视图显示在复选框类别上,但是 all() 方法返回一个数组,该数组的大小与表中现有类别的数量相同,没有任何数据。
$categorias = Categoria::all();
dd($categorias);
return View::make('posts.nuevo')->with('categorias' => $categorias);
这是dd($categorias)的内容:
object(Illuminate\Database\Eloquent\Collection)[218]
protected 'items' =>
array (size=7)
0 =>
object(Categoria)[209]
public 'table' => string 'categorias' (length=10)
public 'timestamps' => boolean false
protected 'fillable' =>
array (size=1)
...
protected 'connection' => null
protected 'primaryKey' => string 'id' (length=2)
protected 'perPage' => int 15
public 'incrementing' => boolean true
protected 'attributes' =>
array (size=2)
...
protected 'original' =>
array (size=2)
...
///// CONTINUE /////
6 =>
object(Categoria)[223]
public 'table' => string 'categorias' (length=10)
public 'timestamps' => boolean false
我在表格中插入了 7 行。
我有一个视图,它使用相同的方法 all() 并正常工作。
我该怎么做才能带我去营地?
【问题讨论】:
-
没错 print_r($categorias->toArray());exit;获取数据使用函数 toArray()