Skip to content

Commit 5ee7ff9

Browse files
author
farhadzand
committed
remove mongodb driver
1 parent 2785442 commit 5ee7ff9

File tree

10 files changed

+83
-438
lines changed

10 files changed

+83
-438
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,20 @@ jobs:
1717
tests:
1818
runs-on: ubuntu-latest
1919

20-
services:
21-
mongodb:
22-
image: mongo:4.4
23-
ports:
24-
- 27017:27017
25-
2620
strategy:
2721
fail-fast: false # Changed to false to see all failures
2822
matrix:
2923
php: [8.2, 8.3, 8.4]
3024
laravel: [11.*, 12.*]
3125
stability: [prefer-lowest, prefer-stable]
32-
db-driver: [mysql, mongodb]
3326
exclude:
3427
# Skip incompatible PHP versions and Laravel versions
3528
- php: 8.2
3629
laravel: 12.*
3730
- php: 8.4
3831
stability: prefer-lowest
3932

40-
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.db-driver }}
33+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }}
4134

4235
steps:
4336
- name: Checkout code
@@ -47,7 +40,7 @@ jobs:
4740
uses: shivammathur/setup-php@v2
4841
with:
4942
php-version: ${{ matrix.php }}
50-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, exif, iconv, mongodb
43+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, exif, iconv
5144
coverage: xdebug
5245
ini-values: error_reporting=E_ALL
5346
tools: composer:v2
@@ -56,17 +49,8 @@ jobs:
5649
run: |
5750
php -v
5851
php -m
59-
echo "MongoDB extension loaded: " $(php -r "echo extension_loaded('mongodb') ? 'Yes' : 'No';")
6052
php --ini
6153
62-
- name: Verify MongoDB Connection
63-
if: matrix.db-driver == 'mongodb'
64-
run: |
65-
# Install MongoDB client to test connection
66-
sudo apt-get update && sudo apt-get install -y mongodb-clients
67-
mongosh --version || echo "mongosh not installed, using mongo"
68-
mongosh --eval "db.version()" mongodb://localhost:27017/test || mongo --eval "db.version()" mongodb://localhost:27017/test
69-
7054
- name: Setup problem matchers
7155
run: |
7256
echo "::add-matcher::/opt/hostedtoolcache/php.json"
@@ -81,19 +65,27 @@ jobs:
8165
uses: actions/cache@v3
8266
with:
8367
path: ${{ steps.composer-cache.outputs.dir }}
84-
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.db-driver }}-${{ hashFiles('**/composer.json') }}-${{ matrix.stability }}
68+
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ hashFiles('**/composer.json') }}-${{ matrix.stability }}
8569
restore-keys: |
86-
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.db-driver }}-${{ hashFiles('**/composer.json') }}-
70+
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-${{ hashFiles('**/composer.json') }}-
8771
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.laravel }}-
8872
89-
- name: Install MongoDB package for Laravel
90-
if: matrix.db-driver == 'mongodb'
91-
run: composer require mongodb/laravel-mongodb:"^4.0" --no-interaction --prefer-dist
73+
- name: Update composer.json for Laravel version
74+
run: |
75+
# Update testbench version for Laravel 12
76+
if [[ "${{ matrix.laravel }}" == "12.*" ]]; then
77+
composer require --no-update "orchestra/testbench:^10.0" --dev
78+
fi
79+
80+
# Update testbench version for Laravel 11
81+
if [[ "${{ matrix.laravel }}" == "11.*" ]]; then
82+
composer require --no-update "orchestra/testbench:^9.0" --dev
83+
fi
9284
9385
- name: Install dependencies
9486
run: |
9587
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
96-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --ignore-platform-req=ext-mongodb
88+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
9789
9890
- name: List installed packages
9991
run: composer show
@@ -120,16 +112,11 @@ jobs:
120112
- name: Run PHPUnit tests
121113
run: |
122114
if [ -f vendor/bin/phpunit ]; then
123-
DRIVER=${{ matrix.db-driver }} vendor/bin/phpunit --coverage-text --verbose
115+
vendor/bin/phpunit --coverage-text --verbose
124116
else
125117
echo "PHPUnit not found, skipping tests"
126118
exit 1
127119
fi
128-
env:
129-
MONGODB_HOST: localhost
130-
MONGODB_PORT: 27017
131-
MONGODB_DATABASE: audit_test
132-
DB_DRIVER: ${{ matrix.db-driver }}
133120
134121
- name: Run PHP Static Analysis
135122
run: |

README.md

Lines changed: 51 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
# Laravel Audit Log
22

3-
A comprehensive entity-level audit logging package for Laravel with support for MySQL and MongoDB databases.
3+
A comprehensive entity-level audit logging package for Laravel with support for MySQL databases.
44

55
## Features
66

7-
-**Multiple Entity Support**: Audit any number of entities with dedicated log tables/collections
8-
-**Database Drivers**: Built-in support for MySQL and MongoDB
7+
-**Multiple Entity Support**: Audit any number of entities with dedicated log tables
8+
-**Database Driver**: Built-in support for MySQL
99
-**Model Log Handling**: Automatic tracking of model changes (create, update, delete, restore)
1010
-**Field Inclusion/Exclusion**: Fine-grained control over which fields to audit
1111
-**Causer Identification**: Automatic tracking of who made the changes
12-
-**Auto-Migration**: Automatic table/collection creation for new entities
12+
-**Auto-Migration**: Automatic table creation for new entities
1313
-**SOLID Principles**: Clean, maintainable, and extensible architecture
1414

1515
## Requirements
1616

1717
- PHP >= 8.2
1818
- Laravel 11.x or 12.x
19-
- MySQL 8.0+ (for MySQL driver)
20-
- MongoDB 4.4+ (for MongoDB driver, optional)
19+
- MySQL 8.0+
2120

2221
## Installation
2322

@@ -37,21 +36,13 @@ php artisan vendor:publish --tag=audit-logger-config
3736

3837
This will create a `config/audit-logger.php` configuration file.
3938

40-
### Step 3: Optional - Install MongoDB Support
41-
42-
If you plan to use MongoDB as a driver, install the MongoDB Laravel package:
43-
44-
```bash
45-
composer require mongodb/laravel-mongodb
46-
```
47-
4839
## Configuration
4940

5041
The configuration file (`config/audit-logger.php`) allows you to customize various aspects of the package:
5142

5243
```php
5344
return [
54-
// Default driver: 'mysql' or 'mongodb'
45+
// Default driver: 'mysql'
5546
'default' => env('AUDIT_DRIVER', 'mysql'),
5647

5748
// Driver configurations
@@ -61,11 +52,6 @@ return [
6152
'table_prefix' => env('AUDIT_TABLE_PREFIX', 'audit_'),
6253
'table_suffix' => env('AUDIT_TABLE_SUFFIX', '_logs'),
6354
],
64-
'mongodb' => [
65-
'connection' => env('AUDIT_MONGODB_CONNECTION', 'mongodb'),
66-
'collection_prefix' => env('AUDIT_COLLECTION_PREFIX', 'audit_'),
67-
'collection_suffix' => env('AUDIT_COLLECTION_SUFFIX', '_logs'),
68-
],
6955
],
7056

7157
// Auto-migration for new entities
@@ -86,6 +72,51 @@ return [
8672
];
8773
```
8874

75+
### Helper Methods for Retrieving Logs
76+
77+
You can add helper methods to your models to make retrieving audit logs easier:
78+
79+
```php
80+
/**
81+
* Get the audit logs for this model.
82+
*/
83+
public function auditLogs(array $options = [])
84+
{
85+
return AuditLogger::getLogsForEntity(
86+
entityType: static::class,
87+
entityId: $this->getKey(),
88+
options: $options
89+
);
90+
}
91+
92+
/**
93+
* Get the most recent audit logs for this model.
94+
*/
95+
public function recentAuditLogs(int $limit = 10)
96+
{
97+
return AuditLogger::getLogsForEntity(
98+
entityType: static::class,
99+
entityId: $this->getKey(),
100+
options: [
101+
'limit' => $limit,
102+
'from_date' => now()->subDays(30)->toDateString(),
103+
]
104+
);
105+
}
106+
107+
/**
108+
* Get audit logs for a specific action.
109+
*/
110+
public function getActionLogs(string $action)
111+
{
112+
return AuditLogger::getLogsForEntity(
113+
entityType: static::class,
114+
entityId: $this->getKey(),
115+
options: ['action' => $action]
116+
);
117+
}
118+
```
119+
89120
## Basic Usage
90121

91122
### Making Models Auditable
@@ -290,63 +321,6 @@ Register it in the config:
290321
],
291322
```
292323

293-
### Using Different Drivers
294-
295-
You can use different drivers for different operations:
296-
297-
```php
298-
// Use MongoDB driver for specific operation
299-
AuditLogger::driver('mongodb')->log(...);
300-
301-
// Use MySQL driver
302-
AuditLogger::driver('mysql')->log(...);
303-
```
304-
305-
### Helper Methods for Retrieving Logs
306-
307-
You can add helper methods to your models to make retrieving audit logs easier:
308-
309-
```php
310-
/**
311-
* Get the audit logs for this model.
312-
*/
313-
public function auditLogs(array $options = [])
314-
{
315-
return AuditLogger::getLogsForEntity(
316-
entityType: static::class,
317-
entityId: $this->getKey(),
318-
options: $options
319-
);
320-
}
321-
322-
/**
323-
* Get the most recent audit logs for this model.
324-
*/
325-
public function recentAuditLogs(int $limit = 10)
326-
{
327-
return AuditLogger::getLogsForEntity(
328-
entityType: static::class,
329-
entityId: $this->getKey(),
330-
options: [
331-
'limit' => $limit,
332-
'from_date' => now()->subDays(30)->toDateString(),
333-
]
334-
);
335-
}
336-
337-
/**
338-
* Get audit logs for a specific action.
339-
*/
340-
public function getActionLogs(string $action)
341-
{
342-
return AuditLogger::getLogsForEntity(
343-
entityType: static::class,
344-
entityId: $this->getKey(),
345-
options: ['action' => $action]
346-
);
347-
}
348-
```
349-
350324
## Database Schema
351325

352326
### MySQL
@@ -370,10 +344,6 @@ CREATE TABLE audit_products_logs (
370344
);
371345
```
372346

373-
### MongoDB
374-
375-
For MongoDB, collections are created with similar fields and appropriate indexes.
376-
377347
## Troubleshooting
378348

379349
### Common Issues
@@ -395,11 +365,6 @@ For MongoDB, collections are created with similar fields and appropriate indexes
395365
- Model uses `Auditable` trait
396366
- Auditing is enabled on the model instance
397367

398-
3. **MongoDB driver issues**: Ensure you've installed the MongoDB package:
399-
```bash
400-
composer require mongodb/laravel-mongodb
401-
```
402-
403368
## Development
404369

405370
### Testing

composer.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iamfarhad/laravel-audit-log",
3-
"description": "Entity-level audit logging package for Laravel with MySQL and MongoDB support",
3+
"description": "Entity-level audit logging package for Laravel with MySQL support",
44
"type": "library",
55
"license": "MIT",
66
"authors": [
@@ -14,14 +14,11 @@
1414
"illuminate/support": "^11.0|^12.0",
1515
"illuminate/database": "^11.0|^12.0",
1616
"illuminate/events": "^11.0|^12.0",
17-
"mongodb/mongodb": "^1.15"
18-
},
19-
"suggest": {
20-
"mongodb/laravel-mongodb": "Required for MongoDB driver support (^4.0|^5.0)"
17+
"illuminate/config": "^11.0|^12.0"
2118
},
2219
"require-dev": {
2320
"phpunit/phpunit": "^10.0|^11.0",
24-
"orchestra/testbench": "^8.0|^9.0",
21+
"orchestra/testbench": "^9.0|^10.0",
2522
"mockery/mockery": "^1.6",
2623
"phpstan/phpstan": "^1.10",
2724
"phpstan/phpstan-strict-rules": "^1.5",
@@ -55,5 +52,10 @@
5552
]
5653
},
5754
"minimum-stability": "stable",
58-
"prefer-stable": true
55+
"prefer-stable": true,
56+
"config": {
57+
"allow-plugins": {
58+
"pestphp/pest-plugin": true
59+
}
60+
}
5961
}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
|--------------------------------------------------------------------------
1010
|
1111
| This option controls the default audit driver that will be used to store
12-
| audit logs. You may set this to any of the drivers defined below.
12+
| audit logs.
1313
|
14-
| Supported: "mysql", "mongodb"
14+
| Supported: "mysql"
1515
|
1616
*/
1717
'default' => env('AUDIT_DRIVER', 'mysql'),
@@ -30,12 +30,6 @@
3030
'table_prefix' => env('AUDIT_TABLE_PREFIX', 'audit_'),
3131
'table_suffix' => env('AUDIT_TABLE_SUFFIX', '_logs'),
3232
],
33-
34-
'mongodb' => [
35-
'connection' => env('AUDIT_MONGODB_CONNECTION', 'mongodb'),
36-
'collection_prefix' => env('AUDIT_COLLECTION_PREFIX', 'audit_'),
37-
'collection_suffix' => env('AUDIT_COLLECTION_SUFFIX', '_logs'),
38-
],
3933
],
4034

4135
/*

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,4 @@ parameters:
1515
identifier: missingType.iterableValue
1616
-
1717
identifier: missingType.generics
18-
# MongoDB related errors (the MongoDB driver uses dynamic methods)
19-
- '#Call to an undefined method Illuminate\\Database\\Connection::collection\(\)#'
20-
- '#Call to an undefined method Illuminate\\Database\\Connection::listCollections\(\)#'
21-
- '#Property iamfarhad\\LaravelAuditLog\\Drivers\\MongoDBDriver::\$databaseName is never read, only written.#'
2218
- '#Construct empty\(\) is not allowed. Use more strict comparison.#'

0 commit comments

Comments
 (0)