Browse Source

fix: validation add & update

pull/1/head
wahyun 8 months ago
parent
commit
d235b95875
  1. 7
      app/Http/Controllers/HumanResourceController.php

7
app/Http/Controllers/HumanResourceController.php

@ -3,7 +3,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Str;
use App\Models\UserToProyek; use App\Models\UserToProyek;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\HumanResource; use App\Models\HumanResource;
@ -18,15 +17,15 @@ class HumanResourceController extends Controller
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'role_id' => 'required',
'name' => 'required', 'name' => 'required',
'ktp_number' => 'required|string|unique:m_users,ktp_number', 'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required', 'employee_type' => 'required',
'company_id' => 'required', 'company_id' => 'required',
'username' => 'unique:m_users,username' 'username' => 'unique:m_users,username',
]); ]);
$data = $request->all(); $data = $request->all();
!$request->is_customer ? $this->validate($request,['role_id'=>'required','divisi_id'=>'required']) : '';
if (isset($request->password) && $request->password != "") { if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password); $data['password'] = md5($request->password);
@ -113,6 +112,8 @@ class HumanResourceController extends Controller
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
!$request->is_customer ? $this->validate($request,['role_id'=>'required','divisi_id'=>'required']) : '';
if (!$id || (int) $id < 0 || $id == "") { if (!$id || (int) $id < 0 || $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