You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
856 B
45 lines
856 B
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
class Couple extends Model
|
|
{
|
|
/**
|
|
* Indicates if the IDs are auto-incrementing.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $incrementing = false;
|
|
|
|
public function husband()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function wife()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function childs()
|
|
{
|
|
return $this->hasMany(User::class, 'parent_id');
|
|
}
|
|
|
|
public function addChild(User $user)
|
|
{
|
|
$user->id = Uuid::uuid4()->toString();
|
|
$user->parent_id = $this->id;
|
|
$user->father_id = $this->husband_id;
|
|
$user->mother_id = $this->wife_id;
|
|
$user->save();
|
|
}
|
|
|
|
public function manager()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|