1
I am setting an attribute of an array, it is accessible only when giving dd()
I do so:
dd($categoria->categoria->NmCategoria)
It works if I do it the natural way like this:
@foreach($subcategorias as $categoria)
<tr>
<td>{{ $categoria->CdSubCategoria }}</td>
<td>{{ $categoria->categoria->NmCategoria }}</td>
</tr>
@endforeach
In my controller I do so:
$subcategorias = SubCategoria::with('categoria')->get();
if(Request::wantsJson())
{
return $subcategorias;
}
else
{
return view('SubCategoria.listSubCategoria', compact('subcategorias'));
}
var_dump
of $subcategorias
:
array(3) { [0]=> array(11) { ["Cdsubcategory"]=> int(1) ["Cdcategory"]=> >int(3) ["Nmsubcategory"]=> string(17) "Gluten-free pie." >["Dscsubcategory"]=> string(40) "Category for gluten-free breads" >["Flgpontua"]=> int(0) ["Qtdpontos"]=> int(1) >["Maxpontosporsubcategory"]=> int(0) ["created_at"]=> string(19) >"2016-09-10 14:25:22" ["updated_at"]=> string(19) "2016-09-14 22:16:03" >["deleted_at"]=> NULL ["category"]=> array(6) { ["Cdcategory"]=> int(3) >["Nmcategoria"]=> string(5) "Bread1" ["Dsccategory"]=> string(31) "Category >intended for breads." ["created_at"]=> string(19) "2016-09-09 00:12:36" >["updated_at"]=> string(19) "2016-09-09 00:12:36" ["deleted_at"]=> NULL } } >[1]=> array(11) { ["Cdsubcategory"]=> int(3) ["Cdcategory"]=> int(5) >["Nmsubcategory"]=> string(29) "Gluten-free and lactose-free cake" >["Dscsubcategory"]=> string(33) "Gluten-free and lactose-free products" >["Flgpontua"]=> int(1) ["Qtdpontos"]=> int(10) >["Maxpontosporsubcategoria"]=> int(0) ["created_at"]=> string(19) >"2016-09-10 20:34:29" ["updated_at"]=> string(19) "2016-09-10 20:34:29" >["deleted_at"]=> NULL ["category"]=> array(6) { ["Cdcategoria"]=> int(5) >["Nmcategoria"]=> string(4) "Bolo" ["Dsccategoria"]=> string(29) "Category >destined for cakes" ["created_at"]=> string(19) "2016-09-10 20:32:45" >["updated_at"]=> string(19) "2016-09-10 20:32:45" ["deleted_at"]=> NULL } >[2]=> array(11) { ["CdSubCategoria"]=> int(4) ["CdCategoria"]=> int(7) >["NmSubCategoria"]=> string(7) "Farinha" ["DscSubCategoria"]=> string(23) >"Farinha para fazer bolo" ["FlgPontua"]=> int(0) ["QtdPontos"]=> int(0) >["MaxPontosPorSubCategoria"]=> int(0) ["created_at"]=> string(19) >"2016-09-21 23:00:26" ["updated_at"]=> string(19) "2016-09-21 23:00:26" >["deleted_at"]=> NULL ["category"]=> NULL } }
it does not work and gives the following error:
Trying to get Property of non-object (View: C: Users Computer Desktop SGLE-Bakery PROJECTS Resources views Subcategory listSubCategory.blade.php)
Because this is happening ?
$subcategorias = SubCategoria::with('categoria')->get();
after that line that is in the one controllervar_dump($subcategorias);
and stick to the question!– novic
updated the question
– Renan Rodrigues
excuse makes a
var_dump($subcategorias->toArray());
!!! so is the collection object gets bad to see the results.– novic
ready already att
– Renan Rodrigues
There are categories that are coming
NULL
, I made an answer!– novic