Laravel-auditing: php artisan schedule:run not creating audits

Created on 30 Apr 2019  路  2Comments  路  Source: owen-it/laravel-auditing

| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 5.5.45
| Package version | 4.1.4
| PHP version | 7.2.14

Actual Behaviour

I have a Job that runs with Laravel scheduler ( php artisan schedule:run) that adds new rows on the database (Model::create([...]))

New rows are not reflected on the audits table.

Expected Behaviour

New rows should be reflected on the audits table.

Steps to Reproduce

  • Create a Job that adds new rows on the DB through an Eloquent model that supports audits:
class MyModel extends Model implements AuditableContract
{
    use Auditable;
...
  • Add your Job to the Console Kernel
class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->job(new DummyJob)->withoutOverlapping()->everyMinute();
...
  • Execute php artisan schedule:run

auditable table does not contain information about the new rows.

Most helpful comment

@Wol you are right. The console config was missing.

Thank you!

...
    /*
    |--------------------------------------------------------------------------
    | Audit Console?
    |--------------------------------------------------------------------------
    |
    | Whether we should audit console events (eg. php artisan db:seed).
    |
    */

    'console' => true, // <- here
];

All 2 comments

Do you have the audit.console config variable set to true in your config\audit.php file??

See the 'Console/CLI and Jobs' section in http://www.laravel-auditing.com/docs/9.0/troubleshooting

@Wol you are right. The console config was missing.

Thank you!

...
    /*
    |--------------------------------------------------------------------------
    | Audit Console?
    |--------------------------------------------------------------------------
    |
    | Whether we should audit console events (eg. php artisan db:seed).
    |
    */

    'console' => true, // <- here
];
Was this page helpful?
0 / 5 - 0 ratings