将数据从一个模型加载到另一个模型,空数组。 Laravel

Load data from one model to another model, empty array. Laravel

我有 Post 和类别模型。当我创建一个新的 Post 时,我想将现有的视线显示在复选框类别上,但是方法 all() returns 数组的大小是 [=26= 中现有类别的数量] 没有任何数据。

    $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

我在 table 中插入了 7 行。

我有一个视图,它使用相同的方法 all() 显示其自身模型类别的所有类别的列表并且工作正常。

我怎样才能带我去营地?

Model::all() 是正确的你只需要从数组中获取数据

Use toArray() to get Data

$categorias = Categoria::all();
print_r($categorias->toArray());exit;
return View::make('posts.nuevo')->with('categorias' => $categorias);