I'm dispatching a delayed job that should created some entries in the database:
$userId = Auth::user() ? Auth::user()->getAuthIdentifier() : null;
$job = new DelayedAddPeopleJob($event, $userId);
dispatch($job)->delay(DelayedAddPeopleJob::DELAY);
After 15 minutes DelayedAddPeopleJob is executed and in there im creating entries in the DB if they do not exist.
AutoAddHistory::firstOrCreate([
AutoAddHistory::MATRIX_ID_COLUMN => $matrixId,
AutoAddHistory::ROLE_ID_COLUMN => $ppr->getRoleId(),
AutoAddHistory::PERSON_ID_COLUMN => $ppr->getPersonId(),
AutoAddHistory::CREATED_BY_COLUMN => $this->placedBy,
]);
In this instance the placedBy is the userId passed to DelayedAddPeopleJob. However when the entries appear in the database after those 15 minutes the CREATED_BY is NULL in the database for some reason.
Am I doing something wrong? I tried to find a solution or similar problem but can't. Tried accessing it via magic method instead on const and it did not help.
Job can't contain a user session data.
For this reason, your condition
$userId = Auth::user() ? Auth::user()->getAuthIdentifier() : null;always goes to false and return null, you have to call the userId in another way.You can store the userID at the parent record table and fetch from here once you need.
Also make sure
CREATED_BYcolumn fillable difined at your model.