Update Lihat Jumlah Kunjungan
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Web\Konfigurasi;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Konfigurasi\FilterLogAktivitasRequest;
|
||||
use App\Models\Konfigurasi\KunjunganPengguna;
|
||||
use App\Models\Konfigurasi\LogAktivitas;
|
||||
use App\Models\Pertanian\Petani;
|
||||
use App\Models\User;
|
||||
@@ -64,6 +65,7 @@ class LogAktivitasController extends Controller
|
||||
'jenis' => self::JENIS,
|
||||
'perPage' => self::PER_PAGE,
|
||||
'namaPetani' => $namaPetani,
|
||||
'kunjungan' => KunjunganPengguna::ringkasan(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Konfigurasi\KunjunganPengguna;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CatatKunjungan
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$response = $next($request);
|
||||
|
||||
$user = $request->user() ?? $request->user('sanctum');
|
||||
if (! $user) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$tanda = today()->toDateString() . ':' . $user->id;
|
||||
|
||||
// Web: tanda di session, tanpa query tambahan
|
||||
if ($request->hasSession()) {
|
||||
if ($request->session()->get('kunjungan_tercatat') !== $tanda) {
|
||||
KunjunganPengguna::catat($user->id);
|
||||
$request->session()->put('kunjungan_tercatat', $tanda);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
// API: tanda di cache sampai akhir hari
|
||||
if (Cache::add("kunjungan:{$tanda}", true, now()->endOfDay())) {
|
||||
KunjunganPengguna::catat($user->id);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user