updated db import, views, and api

This commit is contained in:
Gregorio Chiko Putra
2019-05-11 12:41:25 +07:00
parent e2ce3293e1
commit c66f26457e
8 changed files with 621 additions and 571 deletions

View File

@@ -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