Browse Source

Merge pull request 'upload 2023-10-16' (#205) from staging into master

Reviewed-on: ordo/adw-backend#205
pull/3/head
farhantock 1 year ago
parent
commit
c03dcf4aa2
  1. 3
      app/Http/Controllers/DivisiController.php
  2. 83
      app/Models/Divisi.php

3
app/Http/Controllers/DivisiController.php

@ -21,7 +21,8 @@ class DivisiController extends Controller
$this->validate($request, [ $this->validate($request, [
'name' => 'string|required|unique:m_divisi,name', 'name' => 'string|required|unique:m_divisi,name',
'description' => 'nullable|string', 'description' => 'nullable|string',
'parent' => 'nullable|integer' 'parent' => 'nullable|integer',
'color'=>'nullable|string|max:10'
]); ]);
$data = $request->all(); $data = $request->all();

83
app/Models/Divisi.php

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

Loading…
Cancel
Save