Melakukan Perubahan

This commit is contained in:
Vinsensiaaa
2024-07-03 13:24:28 +07:00
parent 28088683bb
commit 13b009cecf
3 changed files with 73 additions and 1 deletions
@@ -4,6 +4,9 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Session;
use App\Models\Tropd;
use App\Models\User;
use Hash;
use Illuminate\Support\Facades\DB;
use App\Models\AkbSpb23;
use App\Models\AkbPendapatan;
@@ -97,4 +100,42 @@ class PengaturanController extends Controller
]);
}
}
public function updateuser()
{
try{
DB::beginTransaction();
$SKPD = Tropd::where("c_tahun_berakhir",">=",getTA())->orderBy('I_ID','ASC')->get();
foreach($SKPD as $rowSKPD){
$user = User::where("nrk",$rowSKPD["c_opd"])->count();
if ($user == 0 ){
// var_dump($rowSKPD["c_opd"]);
// exit;
$user = new User;
$user->name = $rowSKPD["n_opd"];
$user->nrk = $rowSKPD["c_opd"];
$user->password = Hash::make($rowSKPD["c_opd"]);
$user->role_name = "skpd";
$user->save();
$user->assignRole('skpd');
}
}
DB::commit();
return response()->json([
"success" => true,
"message" => "Data User berhasil disesuaikan!"
]);
}catch(Throwable $e){
DB::rollBack();
return response()->json([
"success" => false,
"message" => "Data User gagal disesuaikan!"
]);
}
}
}