all(), [ 'nama' => 'required|string', 'nisn' => 'required|regex:/^[0-9]+$/', ], [ 'required' => 'Kolom :attribute harus diisi.', 'string' => 'Kolom :attribute tidak sesuai.', 'regex' => 'Kolom :attribute tidak sesuai.', ])->validate(); // Look for the given inputs in the resource $siswa = App\Siswa::where('nama', $request->nama) ->where('nisn', $request->nisn) ->first(); // Redirect with error if not found if (!$siswa || $siswa == null) { return response()->json(['siswa' => 'Siswa tidak ditemukan.'], 404); } // Write to log App\AccessLog::create(['siswa_id' => $siswa->id]); return $siswa; }); Route::get('/access_log', function () { // Get the number of unique access $logs = App\AccessLog::all()->unique()->count(); // Get the total number of available resource $resources = App\Siswa::count(); return response()->json([ 'accessed' => $logs, 'total' => $resources, ]); });