Hi, I followed the install instructions over at http://www.laravel-auditing.com/docs/3.0/installation (there is a typo "php atisan auditing:table" is misspelled, after correcting the misspelling the command would not work.
I attempted to move forward and added these two lines to my user model:
use OwenIt\Auditing\Auditable;
class User extends Authenticatable implements \Tymon\JWTAuth\Contracts\JWTSubject
{
use HasRolesAndAbilities;
use Auditable;
But I am getting this error in the console:
PHP Fatal error: Trait 'OwenIt\Auditing\Auditable' not found in ./app/User.php on line 12
[Symfony\Component\Debug\Exception\FatalErrorException]
Trait 'OwenIt\Auditing\Auditable' not found
Running a quick grep I dont know where this is implemented:
# grep -r Auditable vendor/owen-it/
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: if ($model->isTypeAuditable('created')) {
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: if ($model->isTypeAuditable('saved') || $model->isTypeAuditable('updated')) {
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: if ($model->isTypeAuditable('deleted')) {
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: public function isTypeAuditable($key)
Any thoughts on steps to move forward?
Hi @metaclassing , You added the provider?
'providers' => [
// ...
OwenIt\Auditing\AuditingServiceProvider::class,
],
Correct, my config has this in the providers block:
+ // Audit service provider
+ OwenIt\Auditing\AuditingServiceProvider::class,
I tried dumping composer autoload and clearing out cache, not sure why it wouldn't register? I am on ver 3.0 I believe, I pulled the latest from composer. Thanks!
@metaclassing , please run composer dump-autoload
I tried that again, and it didnt make any difference. After grepping through the code for trait names the only one i could find was AuditingTrait.
I changed my use line in a model to this:
use \OwenIt\Auditing\AuditingTrait;
And I no longer get an error but don't know much about testing this to see if its working... Is this the right thing to use instead of the Auditable one from the install instructions?
Hello @metaclassing , remove the package and install again please.
'providers' => [
//OwenIt\Auditing\AuditingServiceProvider::class,
],
composer remove owen-it/laravel-auditingcomposer require owen-it/laravel-auditing'providers' => [
OwenIt\Auditing\AuditingServiceProvider::class,
],
Sorry for the delay in meeting your problem. You are using version 2.4, Install the package again and your problem will be solved.
Do not worry, the fault was not your.
I removed the old, cleared composers cache, and installed fresh and its still not giving me the current version of 3.x with the Auditable trait:
# composer remove owen-it/laravel-auditing
Dependency "laravel/framework" is also a root requirement, but is not explicitly whitelisted. Ignoring.
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing owen-it/laravel-auditing (3.0.0)
- Removing ramsey/uuid (3.5.0)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
# composer clear-cache
Clearing cache (cache-dir): /home/metaclassing/.composer/cache
Clearing cache (cache-files-dir): /home/metaclassing/.composer/cache/files
Clearing cache (cache-repo-dir): /home/metaclassing/.composer/cache/repo
Cache directory does not exist (cache-vcs-dir):
All caches cleared.
# composer require owen-it/laravel-auditing
Using version ^3.0 for owen-it/laravel-auditing
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing ramsey/uuid (3.5.0)
Downloading: 100%
- Installing owen-it/laravel-auditing (3.0.0)
Downloading: 100%
ramsey/uuid suggests installing ircmaxell/random-lib (Provides RandomLib for use with the RandomLibAdapter)
ramsey/uuid suggests installing ext-libsodium (Provides the PECL libsodium extension for use with the SodiumRandomGenerator)
ramsey/uuid suggests installing ext-uuid (Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator)
ramsey/uuid suggests installing moontoast/math (Provides support for converting UUID to 128-bit integer (in string form).)
ramsey/uuid suggests installing ramsey/uuid-doctrine (Allows the use of Ramsey\Uuid\Uuid as Doctrine field type.)
ramsey/uuid suggests installing ramsey/uuid-console (A console application for generating UUIDs with ramsey/uuid)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
# grep -r Auditable vendor/owen-it/
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: if ($model->isTypeAuditable('created')) {
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: if ($model->isTypeAuditable('saved') || $model->isTypeAuditable('updated')) {
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: if ($model->isTypeAuditable('deleted')) {
vendor/owen-it/laravel-auditing/src/AuditingTrait.php: public function isTypeAuditable($key)
#
Okay, try
rm -rf vendor/owen-it
rm -rf composer.lock
Add laravel-auditing in composer.json
"require": {
//..
"owen-it/laravel-auditing": "3.0.2"
},
composer install
@metaclassing thank you,
you made me see a bug in version v3.0. Please install the package again.
So I spent some time poking it, manually requiring 3.0.2 explained why it would not automagically install via composer: I have laravel 5.2. So I upgraded to laravel 5.3 and now get 3.0.2 installed however have got a SQL issue with one of the statements:
Next Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'old' in 'field list' (SQL: insert into `logs` (`id`, `old`, `new`, `type`, `auditable_id`, `auditable_type`, `user_id`, `route`, `ip_address`, `created_at`) values (f6f19214-29cf-45c8-bbeb-0c660a26619e, {"name":"netmandev"}, {"name":"netmandev2"}, updated, 68, App\Ca\Certificate, 1, https://certbot.domain.com/api/ca/accounts/2/certificates/6810.202.34.71token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2NlcnRib3Qua2lld2l0cGxhemEuY29tL2F0dt8, 2016-09-27 18:07:09, ?)) in /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Connection.php:761
Stack trace:
#0 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Connection.php(717): Illuminate\Database\Connection->runQueryCallback('insert into `lo...', Array, Object(Closure))
#1 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Connection.php(481): Illuminate\Database\Connection->run('insert into `lo...', Array, Object(Closure))
#2 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Connection.php(435): Illuminate\Database\Connection->statement('insert into `lo...', Array)
#3 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2126): Illuminate\Database\Connection->insert('insert into `lo...', Array)
#4 [internal function]: Illuminate\Database\Query\Builder->insert(Array)
#5 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1433): call_user_func_array(Array, Array)
#6 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1583): Illuminate\Database\Eloquent\Builder->__call('insert', Array)
#7 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1472): Illuminate\Database\Eloquent\Model->performInsert(Object(Illuminate\Database\Eloquent\Builder))
#8 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(562): Illuminate\Database\Eloquent\Model->save()
#9 /opt/certbot/vendor/owen-it/laravel-auditing/src/Auditors/DatabaseAuditor.php(19): Illuminate\Database\Eloquent\Model::create(Array)
#10 /opt/certbot/vendor/owen-it/laravel-auditing/src/AuditorManager.php(41): OwenIt\Auditing\Auditors\DatabaseAuditor->audit(Object(App\Ca\Certificate))
#11 /opt/certbot/vendor/owen-it/laravel-auditing/src/Auditor.php(17): OwenIt\Auditing\AuditorManager->audit(Object(App\Ca\Certificate))
#12 /opt/certbot/vendor/owen-it/laravel-auditing/src/Auditable.php(167): App\Ca\Certificate->audit()
#13 /opt/certbot/vendor/owen-it/laravel-auditing/src/Auditable.php(74): App\Ca\Certificate->auditUpdate()
#14 [internal function]: App\Ca\Certificate::OwenIt\Auditing\{closure}(Object(App\Ca\Certificate))
#15 /opt/certbot/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(221): call_user_func_array(Object(Closure), Array)
#16 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1665): Illuminate\Events\Dispatcher->fire('eloquent.saved:...', Array)
#17 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1505): Illuminate\Database\Eloquent\Model->fireModelEvent('eloquent.saved:...', false)
#18 /opt/certbot/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1476): Illuminate\Database\Eloquent\Model->finishSave(Array)
#19 /opt/certbot/app/Http/Controllers/CaController.php(237): Illuminate\Database\Eloquent\Model->save()
#20 [internal function]: App\Http\Controllers\CaController->updateCertificate(Object(Dingo\Api\Http\Request), '2', '68')
The exception seems to be caused by this migration:
2015_08_01_104512_create_log_table.php: $table->text('old_value')->nullable();
Meaning the table has old_value while the current code seems to want the column to be named old. I have 3 migrations that were created as part of this package:
2015_08_01_104512_create_log_table.php
2016_05_22_190217_add_fields_to_log_table.php
2016_09_27_162333_create_audits_table.php
Is there some step missing where the log table is upgraded and columns are renamed?
Thanks
Nevermind I figured it out, i dropped the old log tables completely and removed those migrations as they were from the stale previous version. After flushing out the old stuff and replacing the config file with the current one everything appears to be working. Thanks!
Most helpful comment
Hello @metaclassing , remove the package and install again please.
composer remove owen-it/laravel-auditingcomposer require owen-it/laravel-auditing