updated db import, views, and api
This commit is contained in:
@@ -25,14 +25,23 @@ Route::post('/siswa', function (Request $request) {
|
||||
])->validate();
|
||||
|
||||
// Look for the given inputs in the resource
|
||||
$tanggalLahir = Carbon\Carbon::parse($request->tanggalLahir)->format('Y-m-d');
|
||||
try {
|
||||
$tanggalLahir = Carbon\Carbon::parse($request->tanggalLahir)->format('Y-m-d');
|
||||
} catch(Exception $e) {
|
||||
return response()->json([
|
||||
'message' => 'The given data was invalid.',
|
||||
'errors' => [
|
||||
'tanggalLahir' => ['Kolom tanggal lahir tidak sesuai.'],
|
||||
]
|
||||
], 422);
|
||||
}
|
||||
$siswa = App\Siswa::where('nisn', $request->nisn)
|
||||
->where('tanggal_lahir', $tanggalLahir)
|
||||
->first();
|
||||
|
||||
// Redirect with error if not found
|
||||
if (!$siswa || $siswa == null) {
|
||||
return response()->json(['siswa' => 'Siswa tidak ditemukan.'], 404);
|
||||
return response()->json(['errors' => ['siswa' => ['Siswa tidak ditemukan.']]], 404);
|
||||
}
|
||||
|
||||
// Write to log
|
||||
|
||||
Reference in New Issue
Block a user