1. Go to this page and download the library: Download learncodeweb/activitylog library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
learncodeweb / activitylog example snippets
/*
* Package Service Providers...
*/
Lcw\Activitylog\Providers\ActivityLogProvider::class,
return [
App\Providers\AppServiceProvider::class,
Lcw\Activitylog\Providers\ActivityLogProvider::class, // ✅ Add this line
];
return [
/*
|--------------------------------------------------------------------------
| Delete Limit
|--------------------------------------------------------------------------
| Set how many months of old logs to keep before auto-deletion.
| Default: 3 months
*/
'delete_limit' => 3,
/*
|--------------------------------------------------------------------------
| Ignore Routes
|--------------------------------------------------------------------------
| List route names or URIs where you do NOT want activity to be logged.
| Example: dashboard index, file downloads, etc.
*/
'ignore_routes' => [
'dashboard.index',
'settings.download.history.activity_log',
],
];
use Lcw\Activitylog\ActivityLog;
public function index(Request $request)
{
$activityLog = new ActivityLog();
$logs = $activityLog->get($request);
return view('your-view', compact('logs'));
}
use Lcw\Activitylog\ActivityLog;
$activityLog = new ActivityLog();
// Delete logs older than 1 month
$activityLog->logDelete(1);
// Delete logs older than 3 months
$activityLog->logDelete(3);
use Lcw\Activitylog\ActivityLog;
$activityLog = new ActivityLog();
$activityLog->create([
'log' => 'User updated their notification settings',
'query_string' => $request->all(),
]);
'ignore_routes' => [
'dashboard.index', // by route name
'api/health-check', // by URI
'settings.download.history.activity_log',
],
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Lcw\Activitylog\ActivityLog;
class ActivityLogController extends Controller
{
protected $activityLog;
public function __construct()
{
$this->activityLog = new ActivityLog();
}
// Show all activity logs
public function index(Request $request)
{
$logs = $this->activityLog->get($request);
return view('admin.activity-log', compact('logs'));
}
// Delete logs older than X months
public function deleteOld(Request $request)
{
$months = $request->input('months', 3);
$this->activityLog->logDelete($months);
return back()->with('success', 'Old logs deleted successfully!');
}
// Manually log a custom action
public function logCustomAction()
{
$this->activityLog->create([
'log' => 'Admin exported the user report',
]);
return back()->with('success', 'Action logged!');
}
}
bash
# Pehle publish karo
php artisan vendor:publish --provider="Lcw\Activitylog\Providers\ActivityLogProvider" --tag="migrations"
# Phir tenant folder mein move karo
mv database/migrations/*_create_activity_log_master.php database/migrations/tenant/
bash
# Sab tenants par migrate karo
php artisan tenants:migrate
# Sirf ek specific tenant par migrate karo
php artisan tenants:migrate --tenants=your-tenant-id
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.