wahyuun
1 year ago
1 changed files with 42 additions and 41 deletions
@ -1,41 +1,42 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class Divisi extends Model |
||||
{ |
||||
protected $table = 'm_divisi'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', |
||||
'parent', |
||||
'description', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by' |
||||
]; |
||||
|
||||
public static function boot() { |
||||
parent::boot(); |
||||
|
||||
static::deleting(function($data) { |
||||
$data->children()->delete(); |
||||
}); |
||||
} |
||||
|
||||
public function parent() |
||||
{ |
||||
return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); |
||||
} |
||||
|
||||
public function children() |
||||
{ |
||||
return $this->hasMany('App\Models\Divisi','parent')->with('children'); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class Divisi extends Model |
||||
{ |
||||
protected $table = 'm_divisi'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', |
||||
'parent', |
||||
'description', |
||||
'color', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by' |
||||
]; |
||||
|
||||
public static function boot() { |
||||
parent::boot(); |
||||
|
||||
static::deleting(function($data) { |
||||
$data->children()->delete(); |
||||
}); |
||||
} |
||||
|
||||
public function parent() |
||||
{ |
||||
return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); |
||||
} |
||||
|
||||
public function children() |
||||
{ |
||||
return $this->hasMany('App\Models\Divisi','parent')->with('children'); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue