I've would like to have a table that has a one to many with itself.Eg: I have like a people table that can have many other people.This is how my code looks like:
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();
});
}
And in my Person.php model i have this:
public function people(){
return $this->belongsTo('App\Person')->withDefault();
}
public function person(){
return $this->hasMany('App\Person');
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2TJhcOd
via IFTTT

Aucun commentaire:
Enregistrer un commentaire