When I call my creation method inside the observer it has an Auth::user(), when I call it through an Octane::concurrently
it is null, if I don't use concurrently it works perfectly
ex:
[$contract, $contractType] = Octane::concurrently([
fn() => Contract::create($data, $loadRelationships),
fn() => collect(ContractTypeEnum::cases())
->filter(function ($enum) use ($data) {
return strtolower($enum->label()) === strtolower($data['contract_type']);
})
->first()
->name,
]);
In my observer:
public function creating(ContractModel $contract)
{
// Auth::user() is null
$contract->created_by = Auth::user()->id;
}
if I call create outside concurrently:
$contract = Contract::create($data, $loadRelationships);
In my observer:
public function creating(ContractModel $contract)
{
// Auth::user() is object User model
$contract->created_by = Auth::user()->id;
}
CodePudding user response:
When using concurrent mode, the task/code is handled by the job worker.
In the environment of the job worker there is no session, no user logged in and no cookies.
I suggest you send the user instance as a variable to your concurrent callback function