Php 将数据从一个模型加载到另一个模型,空数组。拉维尔

Php 将数据从一个模型加载到另一个模型,空数组。拉维尔,php,arrays,laravel,model,Php,Arrays,Laravel,Model,我有帖子和分类模型。当我创建一篇新文章时,我希望在复选框类别上显示现有的视图,但是方法all()返回一个数组,该数组的大小等于表中现有类别的数量,而不包含任何数据 $categorias = Categoria::all(); dd($categorias); return View::make('posts.nuevo')->with('categorias' => $categorias); 这是dd($categorias)的内容: 我在表中插入了7

我有帖子和分类模型。当我创建一篇新文章时,我希望在复选框类别上显示现有的视图,但是方法all()返回一个数组,该数组的大小等于表中现有类别的数量,而不包含任何数据

    $categorias = Categoria::all();
    dd($categorias);

    return View::make('posts.nuevo')->with('categorias' => $categorias);
这是dd($categorias)的内容:

我在表中插入了7行

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

我如何才能带我去营地?

Model::all()是正确的,您只需要从该数组中提取数据

使用toArray()获取数据

这是正确的打印($categorias->toArray());出口要获取数据,请使用函数toArray()
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
$categorias = Categoria::all();
print_r($categorias->toArray());exit;
return View::make('posts.nuevo')->with('categorias' => $categorias);