I have the Post and Category models. When I create a new Post I want to take existing sight for display on a checkbox category, but the method all() returns an array 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 content of 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
I have 7 rows inserted into the table.
I have a view that displays the list of all categories of its own model category with the same method all() and working properly.
how I can do to take me the camps?
Model::all() is correct you just need to fetch data out of that Array
Use toArray() to get Data
$categorias = Categoria::all();
print_r($categorias->toArray());exit;
return View::make('posts.nuevo')->with('categorias' => $categorias);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With