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

I have Post and Category models. When I create a new message, I want to use the existing spectacle to display a flag in the category, but the all () method returns an array to the size of the number of existing categories in the table without any data.

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

This is the contents of dd ($ categorization):

 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 

I have 7 rows inserted in a table.

I have a view that displays a list of all categories of its own model category with the same all () method and works correctly.

How can I do to take me to camps?

+5
source share
1 answer

Model :: all () is correct, you just need to extract data from this array

Use toArray () to get data

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

All Articles