And why not just create one entity?
Migration:
Schema::create('categories', function($table)
{
$table->increments('id');
$table->integer('parent_id')->nullable();
$table->string('name');
$table->boolean('inactive')->default(0);
$table->timestamps();
$table->engine = 'InnoDB';
});
Relationships:
/**
* Define an inverse one-to-one or many relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent()
{
return $this->belongsTo('Category', 'parent_id');
}
/**
* Define a one-to-many relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function children()
{
return $this->hasMany('Category', 'parent_id');
}
To create and assign:
$parent = new Category;
$parent->name = 'Parent';
$parent->save();
$child = new Category(['name' = 'Child']);
$parent->children()->save($child);
It's simpler!