Depending on the title
and details you described in your question makes me think that, you want to create a relationship to the model itself using another field/column of the same model and the id
field and in this case you may create such a relationship using something like this:
class Category extends Eloquent {
public function recipes()
{
return $this->hasMany('Category', 'category_id');
}
}
According to this relationship, your categories
table should contain primary key id
and another field as category_id
to make relation so, if an id
is 1
and if category_id
contains the 1
then there is a relation between id=1
and category_id=1
.
I've written an article a few days ago on this same thing, you may read that to get the better idea that I'm talking about: LARAVEL – MODEL RELATIONSHIP TO ITSELF.