Browse Source

update validation name

pull/1/head
farhantock 1 year ago
parent
commit
6bb424b6fd
  1. 11
      app/Http/Controllers/DivisiController.php
  2. 5
      app/Http/Controllers/RoleController.php

11
app/Http/Controllers/DivisiController.php

@ -8,7 +8,8 @@ use App\Models\Divisi;
class DivisiController extends Controller class DivisiController extends Controller
{ {
private function getAllChildren($divisi, $depth = 0, $array = []) { private function getAllChildren($divisi, $depth = 0, $array = [])
{
$divisi->depth = $depth; $divisi->depth = $depth;
array_push($array, $divisi); array_push($array, $divisi);
foreach ($divisi->children as $child) { foreach ($divisi->children as $child) {
@ -17,9 +18,10 @@ class DivisiController extends Controller
return $array; return $array;
} }
public function add(Request $request){ public function add(Request $request)
{
$this->validate($request, [ $this->validate($request, [
'name' => 'string|required|unique:m_divisi,name', 'name' => 'string|required|unique:m_divisi,name,NULL,id,company_id,' . $request->input('company_id'),
'description' => 'nullable|string', 'description' => 'nullable|string',
'parent' => 'nullable|integer', 'parent' => 'nullable|integer',
'color' => 'nullable|string|max:10' 'color' => 'nullable|string|max:10'
@ -36,7 +38,8 @@ class DivisiController extends Controller
return response()->json(['status' => 'success', 'message' => 'Data created!', 'code' => 200]); return response()->json(['status' => 'success', 'message' => 'Data created!', 'code' => 200]);
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
{
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);

5
app/Http/Controllers/RoleController.php

@ -11,7 +11,7 @@ class RoleController extends Controller
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'name' => 'string|required|unique:m_roles,name', 'name' => 'string|required|unique:m_roles,name,NULL,id,company_id,' . $request->input('company_id'),
'description' => 'required' 'description' => 'required'
]); ]);
@ -30,7 +30,8 @@ class RoleController extends Controller
return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200);
} }
public function edit( $id){ public function edit($id)
{
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);

Loading…
Cancel
Save