Add auditable_type and auditable_id properties to Audit Model#1025
Merged
erikn69 merged 2 commits intoowen-it:masterfrom May 21, 2025
Merged
Add auditable_type and auditable_id properties to Audit Model#1025erikn69 merged 2 commits intoowen-it:masterfrom
auditable_type and auditable_id properties to Audit Model#1025erikn69 merged 2 commits intoowen-it:masterfrom
Conversation
erikn69
approved these changes
May 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EDIT: imported Carbon, apparently I missed that last time. Sorry 😬
Hi, Another addition to the Audit docblock to help with PHPStan type hinting.
This one is to add the
auditable_typeandauditable_idcolumns used for theauditablerelation so they can be selcted, plucked, etc. The reason for this is an example below:In PHPStan levels 7 and above, this gives the following error:
Adding the properties to the Audit model resolves this. From looking at the migration stub, the morphable prefix for the auditable column cannot be changed so there shouldn't be a risk of these type hinted properties being incorrect.
User Properties
I haven't made the same change for the
userrelation. The reason why is that the config (and migration) allows for altering the prefix of the user morph column.laravel-auditing/config/audit.php
Lines 27 to 34 in c57fbec
laravel-auditing/database/migrations/audits.stub
Lines 21 to 24 in c57fbec
Therefore, trying to type hint them would be unreliable, as they can be changed.