Closed eComEvo closed 1 year ago
Change the morph_prefix to singular user and try viewing the resource that now has an audit record, then change it back to the plural form.
Why would you change morph_prefix
?
It's supposed to be fixed, because it's a database field
https://github.com/owen-it/laravel-auditing/blob/7d09546436ff3317edc899362c9bc20af27be39c/config/audit.php#L27-L28
https://github.com/owen-it/laravel-auditing/blob/7d09546436ff3317edc899362c9bc20af27be39c/database/migrations/audits.stub#L21-L25
I ordinarily wouldn't change morph_prefix
....except that I figured out that the plurality difference was the only thing causing the audit relationship to break.
If I leave it as the default user
value then none of the audit relationships load and instead give the error Class "users" not found
...but if I change it to users
then that fixes the loading issue but causes an issue with saving new audit records as I detailed above.
if you are going to change the morph_prefix
you have to change the database field name too, this is not a bug
If I don't change the morph_prefix
then the audit relationships don't load because Class "users" not found
You are mixing two different things, Class "users" not found
means that the class aliases User::getMorphClass()
is not correct, morph_prefix
is an alias for the database fields, this shouldn't necessarily be equal with the morph class
Let morph_prefix
same as db fields, and check your morph class, enforcing-morph-maps-in-laravel, custom-polymorphic-types
if you don't want to check anything, you could also change all the db data in the $morphPrefix . '_type'
field to mach the correct User::getMorphClass()
You're right, there was an issue with the morph maps being incorrectly defined. I fixed the definition and that resolved the problem. Sorry for the mistaken report.
Actual Behaviour
Instead of creating a new audit record when Laravel Nova creates a record, it gives this error:
The
users_id
column should actually beuser_id
.If I change the
morph_prefix
inconfig/audit.php
touser
(singular) it resolves the creation error. However, doing so then causes a retrieval error when the model is loaded with the audits relation and we get this error instead:To see the new audit relation I then have to re-edit the
config/audit.php
file to change themorph_prefix
back tousers
(plural). However, this will then break all future audit record creations.Expected Behaviour
Having the
morph_prefix
match the value returned in theUser::getMorphClass()
method would allow it to save a new audit record and retrieve that audit relation without having to change themorph_prefix
each time.Steps to Reproduce
Install Laravel Nova v4 with the auditing package.
Apply the Auditable class to a model and then add this to the related auditable Laravel Nova resource:
Add a Nova
Audit
resource:Try creating a new resource in Nova that is auditable while
morph_prefix
is set to the plural form ofusers
then change back to the singular form.Change the
morph_prefix
to singularuser
and try viewing the resource that now has an audit record, then change it back to the plural form.