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.
36 lines
753 B
36 lines
753 B
<?php |
|
|
|
namespace App\Models; |
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
class Divisi extends Model |
|
{ |
|
protected $table = 'm_divisi', $guarded = ['id']; |
|
protected $with = ['parent', 'children']; |
|
protected $casts = [ |
|
'id' => 'integer', |
|
'parent' => 'integer' |
|
]; |
|
const CREATED_AT = 'created_at'; |
|
const UPDATED_AT = 'updated_at'; |
|
|
|
public static function boot() |
|
{ |
|
parent::boot(); |
|
|
|
static::deleting(function ($data) { |
|
$data->children()->delete(); |
|
}); |
|
} |
|
|
|
public function parent() |
|
{ |
|
return $this->belongsTo(self::class, 'parent')->where('parent', null); |
|
} |
|
|
|
public function children() |
|
{ |
|
return $this->hasMany(self::class, 'parent'); |
|
} |
|
}
|
|
|