rel*_*ien 5 php arrays model laravel
我有Post和Category模型.当我创建一个新帖子时,我希望在复选框类别上显示现有视线,但方法all()返回一个数组,表中没有任何数据的表中现有类别数量的大小.
$categorias = Categoria::all();
dd($categorias);
return View::make('posts.nuevo')->with('categorias' => $categorias);
Run Code Online (Sandbox Code Playgroud)
这是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
Run Code Online (Sandbox Code Playgroud)
我有7行插入表中.
我有一个视图,显示其自己的模型类别的所有类别的列表,使用相同的方法all()并正常工作.
我怎么能带我去营地?
Model :: all()是正确的,你只需要从该数组中获取数据
使用toArray()获取数据
$categorias = Categoria::all();
print_r($categorias->toArray());exit;
return View::make('posts.nuevo')->with('categorias' => $categorias);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
700 次 |
| 最近记录: |