Laravel Eloquent, adds an attribute that has the same name with a relation

<?php 

class Product extends Eloquent {

protected appends = array('category');

  public function category()
  {
    return $this->belongsTo('Models\Category',
                            'category_id');
  }

}

How to do it?

+4
source share
1 answer
<?php 

class Product extends Eloquent {

  protected $with = array('category');
  //protected $appends = array('category');

  public function category()
  {
    return $this->belongsTo('Models\Category',
                            'category_id');
  }

}

Define a property $withinstead of a property $appends. This is a heavy load.

+4
source

Source: https://habr.com/ru/post/1527486/


All Articles