fix: route 404 store akun karena name sama
This commit is contained in:
parent
7a1bbb020d
commit
f802ea5feb
|
|
@ -27,20 +27,24 @@ public function create()
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'role' => 'required|in:guru,wali_murid',
|
'role' => 'required|in:guru,wali_murid',
|
||||||
'user_id' => 'required',
|
'user_guru_id' => 'required',
|
||||||
|
'user_wali_id' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->role == 'guru') {
|
if ($request->role == 'guru') {
|
||||||
$data = Guru::findOrFail($request->user_id);
|
$data = Guru::findOrFail($request->user_guru_id);
|
||||||
$name = $data->nama_guru;
|
$name = $data->nama_guru;
|
||||||
$email = $data->email ?? strtolower(str_replace(' ', '', $data->nama_guru)) . '@paud.local';
|
$email = $data->email ?? strtolower(str_replace(' ', '', $data->nama_guru)) . '@paud.local';
|
||||||
$data = WaliMurid::findOrFail($request->user_id);
|
$data = WaliMurid::findOrFail($request->user_wali_id);
|
||||||
$name = $data->nama_wali;
|
$name = $data->nama_wali;
|
||||||
$email = $data->email ?? strtolower(str_replace(' ', '', $data->nama_wali)) . '@paud.local';
|
$email = $data->email ?? strtolower(str_replace(' ', '', $data->nama_wali)) . '@paud.local';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (User::where('email', $email)->exists()) {
|
if (User::where('email', $email)->exists()) {
|
||||||
return back()->with('error', 'Email sudah digunakan untuk akun lain.');
|
return back()->with('error', 'Email sudah digunakan untuk akun lain.');
|
||||||
}
|
}
|
||||||
|
|
@ -54,6 +58,7 @@ public function store(Request $request)
|
||||||
|
|
||||||
$data->update(['user_id' => $user->id]);
|
$data->update(['user_id' => $user->id]);
|
||||||
|
|
||||||
|
|
||||||
return redirect()->route('akun.index')->with('success', 'Akun berhasil dibuat!');
|
return redirect()->route('akun.index')->with('success', 'Akun berhasil dibuat!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
<h1 class="text-xl font-semibold text-gray-700 mb-4">➕ Tambah Akun</h1>
|
<h1 class="text-xl font-semibold text-gray-700 mb-4">➕ Tambah Akun</h1>
|
||||||
|
|
||||||
<form action="{{ route('akun.store') }}" method="POST">
|
<form action="{{ route('akun.store') }}" method="POST">
|
||||||
|
|
||||||
@csrf
|
@csrf
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
|
|
@ -17,7 +18,7 @@
|
||||||
|
|
||||||
<div id="guruSelect" class="mb-4">
|
<div id="guruSelect" class="mb-4">
|
||||||
<label class="block text-gray-700 font-medium mb-1">Pilih Guru</label>
|
<label class="block text-gray-700 font-medium mb-1">Pilih Guru</label>
|
||||||
<select name="user_id" class="w-full border-gray-300 rounded-lg p-2">
|
<select name="user_guru_id" class="w-full border-gray-300 rounded-lg p-2">
|
||||||
@foreach ($gurus as $guru)
|
@foreach ($gurus as $guru)
|
||||||
<option value="{{ $guru->id }}">{{ $guru->nama_guru }}</option>
|
<option value="{{ $guru->id }}">{{ $guru->nama_guru }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
@ -26,13 +27,16 @@
|
||||||
|
|
||||||
<div id="waliSelect" class="mb-4 hidden">
|
<div id="waliSelect" class="mb-4 hidden">
|
||||||
<label class="block text-gray-700 font-medium mb-1">Pilih Wali Murid</label>
|
<label class="block text-gray-700 font-medium mb-1">Pilih Wali Murid</label>
|
||||||
<select name="user_id" class="w-full border-gray-300 rounded-lg p-2">
|
<select name="user_wali_id" class="w-full border-gray-300 rounded-lg p-2">
|
||||||
@foreach ($waliMurids as $wali)
|
@foreach ($waliMurids as $wali)
|
||||||
<option value="{{ $wali->id }}">{{ $wali->nama_wali }}</option>
|
<option value="{{ $wali->id }}">{{ $wali->nama_wali }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- with error -->
|
||||||
|
<div class="text-red-600">
|
||||||
|
{{ session('error') }}
|
||||||
|
</div>
|
||||||
<div class="flex justify-end gap-3">
|
<div class="flex justify-end gap-3">
|
||||||
<a href="{{ route('akun.index') }}" class="bg-gray-500 text-white px-4 py-2 rounded hover:bg-gray-600">Batal</a>
|
<a href="{{ route('akun.index') }}" class="bg-gray-500 text-white px-4 py-2 rounded hover:bg-gray-600">Batal</a>
|
||||||
<button type="submit" class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700">Simpan</button>
|
<button type="submit" class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700">Simpan</button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue