Updated ERP with new modules and features
This commit is contained in:
42
app/Http/Controllers/ActivityLogController.php
Normal file
42
app/Http/Controllers/ActivityLogController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ActivityLogController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = ActivityLog::with(['user', 'loggable'])->latest();
|
||||
|
||||
// 1. Filter by Action
|
||||
if ($request->filled('action_type')) {
|
||||
$query->where('action', $request->action_type);
|
||||
}
|
||||
|
||||
// 2. Filter by Date Range
|
||||
if ($request->filled('date_from')) {
|
||||
$query->whereDate('created_at', '>=', $request->date_from);
|
||||
}
|
||||
if ($request->filled('date_to')) {
|
||||
$query->whereDate('created_at', '<=', $request->date_to);
|
||||
}
|
||||
|
||||
// 3. Search by User or Entity Type
|
||||
if ($request->filled('search')) {
|
||||
$searchTerm = $request->search;
|
||||
$query->where(function ($q) use ($searchTerm) {
|
||||
$q->whereHas('user', function ($userQuery) use ($searchTerm) {
|
||||
$userQuery->where('name', 'like', '%' . $searchTerm . '%');
|
||||
})
|
||||
->orWhere('loggable_type', 'like', '%' . $searchTerm . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$logs = $query->paginate(20)->withQueryString();
|
||||
|
||||
return view('activity-logs.index', compact('logs'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user