Laravel 5.2 returns associative array instead of Object in belongsTo

0
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Categoria extends Model
{
protected $fillable=["descripcion","categoria_id"];

public function recurso_categorias(){
    return $this->hasMany('App\RecursoCategoria');
}

public function categorias(){
    return $this->hasMany('App\Categoria');
}

public function categoria(){
    return $this->belongsTo('App\Categoria');
}
}

When I execute $categoria->categorias , it returns a collection of objects of the Class category. However, when I run $categoria->categoria it returns an associative array instead of a category class.

I should do this:

 $categoria->categoria->descripcion // esto no funciona

but it does this:

 $categoria->categoria["descripcion"] // esto si funciona

Do you know what's going on? Why do not you return an object of the category category? Any way to solve it?

    
asked by Flor 26.04.2016 в 05:46
source

0 answers