Browse Source

fix search table,add divisi,edit divisi

pull/3/head
wahyuun 1 year ago
parent
commit
afd447cdd3
  1. 25
      app/Http/Controllers/DivisiController.php

25
app/Http/Controllers/DivisiController.php

@ -19,9 +19,9 @@ class DivisiController extends Controller
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'name' => 'required', 'name' => 'string|required|unique:m_divisi,name',
'description' => 'string', 'description' => 'nullable|string',
'parent' => 'integer' 'parent' => 'nullable|integer'
]); ]);
$data = $request->all(); $data = $request->all();
@ -39,8 +39,15 @@ class DivisiController extends Controller
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$this->validate($request, [
'name' => 'string|required',
'description' => 'nullable|string',
'parent' => 'nullable|integer'
]);
$data = Divisi::find($id); $data = Divisi::find($id);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : '';
if(!$data) if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
@ -70,10 +77,16 @@ class DivisiController extends Controller
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
} }
public function search() public function search(Request $request)
{ {
return $this->list(); $payload = $request->all();
// cant use builder for this case $dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
public function list() public function list()

Loading…
Cancel
Save