You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 11, 2023. It is now read-only.
I am attempting to use a Laravel Observer to perform an action on the Creating and/or Created step of a models lifecycle. In this created() method, I am trying to determine if the model has been saved as a draft, or created fully (i.e. published), and perform a different action based on this.
I seem to be unable to do this, as the $model->published property is always $false and other properties like $model->draft or $model->draft_parent_id aren't populated at these stages. Published being $false certainty makes sense in creating(), but surely not in created()? I have also tried saved() for good measure - but it was also false there.
It seems the published flag is only set after all other stages have completed somehow, and I am not sure of the mechanism through which it does this - as I can't tell when the /draft-publish endpoints are called for the DraftController to set published to $true.
To Reproduce
Steps to reproduce the behavior:
Create an observer for a pre-existing model you have, mine was Report:
Implement an Observer lifecycle stage (i.e. saving/creating/created/saved):
namespaceApp\Observers;
useApp\Report;
useIlluminate\Support\Facades\Log;
classReportObserver
{
publicfunctioncreated(Report$report){
Log::info($report);
Log::info($report->published); // This always returns falseLog::info($report->draft); // This is always nullLog::info($report->draft_parent_id); // This is always null
}
}
Expected behavior
There should be a mechanism made available to determine if a model object is a unpublished / published item (i.e. draft) in an Observer.
Screenshots
Environment(please complete the following information):
PHP version: [7.4 & 8.0]
Laravel Nova Version [3.29.0]
Version [1.1.4]
Additional context
N/A
The text was updated successfully, but these errors were encountered:
Describe the bug
I am attempting to use a Laravel Observer to perform an action on the
Creating
and/orCreated
step of a models lifecycle. In thiscreated()
method, I am trying to determine if the model has been saved as a draft, or created fully (i.e. published), and perform a different action based on this.I seem to be unable to do this, as the
$model->published
property is always$false
and other properties like$model->draft
or$model->draft_parent_id
aren't populated at these stages. Published being$false
certainty makes sense increating()
, but surely not increated()
? I have also triedsaved()
for good measure - but it was also false there.It seems the published flag is only set after all other stages have completed somehow, and I am not sure of the mechanism through which it does this - as I can't tell when the
/draft-publish
endpoints are called for theDraftController
to set published to$true
.To Reproduce
Steps to reproduce the behavior:
Report
:Expected behavior
There should be a mechanism made available to determine if a model object is a unpublished / published item (i.e. draft) in an Observer.
Screenshots
Environment(please complete the following information):
Additional context
N/A
The text was updated successfully, but these errors were encountered: