0

I am trying to insert some logic when the 'creating' event is fired in the User model of a Laravel/Voyager application, here's my code:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends \TCG\Voyager\Models\User
{ 
use Notifiable;

public static function boot()
{
    parent::boot();

    // over-ride the creating event
    static::creating(function($user)
    {
      $user->created_by = auth()->user() ? auth()->user()->id : null;
    });

    // over-ride the updating event
    static::updating(function($user)
    {
      $user->updated_by = auth()->user() ? auth()->user()->id : null;
    });
}

}

But it looks like the 'creating' event is never called, while the 'boot' method is called. Anyone has got any idea why ? Thanks in advance!

GiulioG
  • 369
  • 4
  • 15

1 Answers1

3

For anyone that will be stuck in the same situation: you have to tell Voyager which model/class to use in the BREAD settings, otherwise Voyager will always use \TCG\Voyager\Models\User .

GiulioG
  • 369
  • 4
  • 15