Superadmin boleh padam pengguna
- Butang Padam dalam senarai pengguna (dengan pengesahan) - Tidak boleh padam akaun sendiri — dipapar '(akaun anda)' - Tidak boleh padam pengguna yang telah mencatat rekod kehadiran (disokong FK dicatat_oleh_user_id di peringkat DB) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\KehadiranKtm;
|
||||
use App\Models\Sppm\Dun;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -65,4 +66,21 @@ class PenggunaController extends Controller
|
||||
|
||||
return redirect()->route('pengguna.index')->with('status', 'Pengguna baharu berjaya didaftarkan.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, User $pengguna)
|
||||
{
|
||||
if ($pengguna->id === $request->user()->id) {
|
||||
return back()->withErrors(['pengguna' => 'Anda tidak boleh memadam akaun anda sendiri.']);
|
||||
}
|
||||
|
||||
if (KehadiranKtm::where('dicatat_oleh_user_id', $pengguna->id)->exists()) {
|
||||
return back()->withErrors([
|
||||
'pengguna' => "Pengguna {$pengguna->name} tidak boleh dipadam kerana telah mencatat rekod kehadiran.",
|
||||
]);
|
||||
}
|
||||
|
||||
$pengguna->delete();
|
||||
|
||||
return redirect()->route('pengguna.index')->with('status', "Pengguna {$pengguna->name} telah dipadam.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user