Skip to content

Commit 063103d

Browse files
committed
first commit
1 parent 5055fd4 commit 063103d

File tree

3 files changed

+157
-47
lines changed

3 files changed

+157
-47
lines changed

README.md

Lines changed: 139 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,148 @@
1-
<h1 align="center">Laravel User Activity</h1>
2-
<p align="center"><a href="https://packagist.org/packages/haruncpi/laravel-user-activity"><img src="https://badgen.net/packagist/v/haruncpi/laravel-user-activity" /></a>
3-
<a href="https://creativecommons.org/licenses/by/4.0/"><img src="https://badgen.net/badge/licence/CC BY 4.0/23BCCB" /></a>
4-
<a href=""><img src="https://badgen.net/packagist/dt/haruncpi/laravel-user-activity"/></a>
5-
<a href="https://twitter.com/laravelarticle"><img src="https://badgen.net/badge/twitter/@laravelarticle/1DA1F2?icon&label" /></a>
6-
<a href="https://facebook.com/laravelarticle"><img src="https://badgen.net/badge/facebook/laravelarticle/3b5998"/></a>
7-
</p>
1+
Features of Laravel User Activity
2+
---------------------------------
83

9-
<p align="center">Easily monitor your user activity with beautiful responsive & easy user-interface!</p>
4+
* Beautiful, responsive and easy UI.
5+
* Easy installation to existing or new Laravel application.
6+
* Monitor record edit, record delete, login and lockout activity.
7+
* Filtering user activity logs.
8+
* Configurable routes.
9+
* Custom middleware support.
10+
* Console command for activity log clear.
1011

11-
![Image description](previews/preview.png)
12+
Installation
13+
------------
1214

13-
## Documentation
14-
Checkout features & full documentation of [Laravel User Activity](https://laravelarticle.com/laravel-user-activity)
15+
Step 1 Run this command given below to install the laravel user activity package.
1516

16-
## Other Packages
17-
- [Laravel H](https://github.com/haruncpi/laravel-h) - A helper package for Laravel Framework.
18-
- [Laravel ID generator](https://github.com/haruncpi/laravel-id-generator) - A laravel package for custom database ID generation.
19-
- [Laravel Simple Filemanager](https://github.com/haruncpi/laravel-simple-filemanager) - A simple filemanager for Laravel.
20-
- [Laravel Option Framework](https://github.com/haruncpi/laravel-option-framework) - Option framework for Laravel.
17+
```
18+
composer require haunv/laravel-user-activity
19+
```
2120

22-
### Change Log
2321

24-
v1.0.6
25-
- Default user model `App\Models\User` to support laravel >=8
26-
- Carbon date parse instead of $dates cast.
22+
Step 2 Now run this artisan command.
2723

28-
v1.0.4
29-
- Completely enable or disable logging by `activated` config value
30-
- Added Base model logging compatibility
24+
```
25+
php artisan user-activity:install
26+
```
3127

32-
v1.0.3
33-
- Minor improvements
3428

35-
v1.0.2
36-
- Create log type added
37-
- User model configuration
38-
- UI ajax loading indicator
29+
Installation finished!
30+
31+
Usages
32+
------
33+
34+
By default, It will catch login activity and lockout (too many attempts) automatically. You can enable or disable it by config value. To keep track of your existing table record edit and delete, just use the `Loggable` trait in your model. That's it, super simple! If any user edits or delete your existing table record, it will automatically be logged into the `logs` table and you will get the details, what data deleted or edited by users.
35+
36+
```
37+
<?php namespace App;
38+
39+
use Illuminate\Database\Eloquent\Model;
40+
use Haruncpi\LaravelUserActivity\Traits\Loggable;
41+
42+
class Student extends Model
43+
{
44+
use Loggable;
45+
46+
}
47+
```
48+
49+
50+
![activity-log-details-preview.png](https://laravelarticle.com/site/images/1px.png)
51+
52+
To view user activity dashboard, browse the `/admin/user-activity`. By default, only logged in user can view the user activity dashboard. You can add any middleware restriction by `user-activity.php` config file.
53+
54+
```
55+
http://example.com/admin/user-activity
56+
```
57+
58+
59+
**Dashboard Preview**
60+
61+
![user-activity-dashboard.png](https://laravelarticle.com/site/images/1px.png)
62+
63+
Available console command
64+
-------------------------
65+
66+
To delete activity log data older than defined days value into the `user-activity.php` config file (default value: 7 days).
67+
68+
```
69+
php artisan user-activity:delete
70+
```
71+
72+
73+
To delete activity log data older than n days.
74+
75+
```
76+
php artisan user-activity:delete 30
77+
```
78+
79+
80+
To delete all activity log data
81+
82+
```
83+
php artisan user-activity:delete all
84+
```
85+
86+
87+
N.B With the help of these console commands, you can make a laravel schedule for deleting user activity log data automatically. If you are a shared hosting (cPanel) user then you can read the [laravel schedule in the shared hosting](https://laravelarticle.com/laravel-scheduler-on-cpanel-shared-hosting) tutorial post.
88+
89+
Customization
90+
-------------
91+
92+
Change the config value according to your need into the `user-activity.php` config file to customize activity log dashboard URL, custom middleware and activity log enable or disable. Default config values are given below.
93+
94+
```
95+
<?php
96+
97+
return [
98+
'activated' => true,
99+
'middleware' => ['web', 'auth'],
100+
'route_path' => 'admin/user-activity',
101+
'admin_panel_path' => 'admin/dashboard',
102+
'delete_limit' => 7,
103+
104+
'model' => [
105+
'user' => "App\User"
106+
],
107+
108+
'log_events' => [
109+
'on_edit' => true,
110+
'on_delete' => true,
111+
'on_login' => true,
112+
'on_lockout' => true
113+
]
114+
];
115+
```
116+
117+
118+
Note: You can configure your user instance. For Laravel 8, use it `App\Models\User`
119+
120+
Hope this package will help you to monitor your application user activity with a beautiful and easy UI. The laravel user activity package is an open-source laravel package with CC 4.0 licence. Support the [Laravel User Activity package](https://github.com/haruncpi/laravel-user-activity) GitHub repository to make it better.
121+
122+
### Base Model Class Configuration
123+
124+
Suppose, you have a parent model class extends by the laravel eloquent model class and it has a lot of sub-class. In this situation, you can easily configure the Larave User Activity package with your base model class implementation.
125+
126+
Use Loggable trait In your base model class
127+
128+
```
129+
class BaseModel extends Model
130+
{
131+
use Loggable;
132+
133+
...
134+
...
135+
}
136+
```
137+
138+
139+
Now all the sub-class of the base model will be automatically logged! In case, If you don't want to log for any subclass of the base model just add a property to exclude logging.
140+
141+
```
142+
class B extends BaseModel
143+
{
144+
public $excludeLogging = true;
145+
...
146+
...
147+
}
148+
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "haruncpi/laravel-user-activity",
3-
"description": "Monitor user activity easily!",
2+
"name": "haunv/laravel-user-activity",
3+
"description": "Monitor user activity easily! for laravel 12",
44
"license": "cc-by-4.0",
55
"keywords": [
66
"laravel",

src/Controllers/ActivityController.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public function __construct()
1919

2020
private function handleData(Request $request)
2121
{
22-
$this->validate($request, [
23-
'action' => 'required|string',
24-
'user_id' => 'sometimes|numeric',
25-
'log_type' => 'sometimes|string',
26-
'table' => 'sometimes|string',
27-
'from_date' => 'sometimes|date_format:Y-m-d',
28-
'to_date' => 'sometimes|date_format:Y-m-d'
29-
]);
22+
// $this->validate($request, [
23+
// 'action' => 'required|string',
24+
// 'user_id' => 'sometimes|numeric',
25+
// 'log_type' => 'sometimes|string',
26+
// 'table' => 'sometimes|string',
27+
// 'from_date' => 'sometimes|date_format:Y-m-d',
28+
// 'to_date' => 'sometimes|date_format:Y-m-d'
29+
// ]);
3030

3131
$data = Log::with('user')->orderBy('id', 'desc');
3232
if ($request->has('user_id')) {
@@ -49,11 +49,11 @@ private function handleData(Request $request)
4949

5050
private function handleCurrentData(Request $request)
5151
{
52-
$this->validate($request, [
53-
'table' => 'required|string',
54-
'id' => 'required',
55-
'log_id' => 'required|numeric'
56-
]);
52+
// $this->validate($request, [
53+
// 'table' => 'required|string',
54+
// 'id' => 'required',
55+
// 'log_id' => 'required|numeric'
56+
// ]);
5757

5858
$table = request('table');
5959
$id = request('id');
@@ -72,9 +72,9 @@ private function handleCurrentData(Request $request)
7272

7373
private function handleUserAutocomplete(Request $request)
7474
{
75-
$this->validate($request, [
76-
'user' => 'required|string|max:50'
77-
]);
75+
// $this->validate($request, [
76+
// 'user' => 'required|string|max:50'
77+
// ]);
7878

7979
$user = request('user');
8080
return $this->userInstance::select('id', 'name', 'email')

0 commit comments

Comments
 (0)