Я хотел бы иметь table
, который имеет one to many
с собой. Например: у меня есть people table
, в котором может быть много других people
. Вот так выглядит мой код:
public function up()
{
Schema::create('people', function (Blueprint $table) {
$table->string('id')->primary();//Here my PK is a string
$table->string('name');
$table->string('title')->nullable();
$table->string('parent_id');//Here is the foreign key of another person
$table->timestamps();
});
}
И в моей модели Person.php у меня есть это:
public function people()
{
return $this->belongsTo('App\Person')->withDefault();
}
public function person()
{
return $this->hasMany('App\Person');
}
Посмотрите на это изображение:
![The relashionship that i'm trying to implement](https://i.stack.imgur.com/8wufx.jpg)