How to create self referential relationship in laravel?

前端 未结 4 864
臣服心动
臣服心动 2020-12-02 18:03

I am new to Laravel. I Just want to create a self referential model. For example, I want to create a product category in which the field parent_id as same as pr

4条回答
  •  伪装坚强ぢ
    2020-12-02 18:42

    you can refer self, using $this

    class Post extends Eloquent {
    
        function posts(){
            return $this->hasMany($this, 'parent_id');
        }
    }
    

提交回复
热议问题