Laravel-auditing: Get the relationship username from a audit

Created on 20 Nov 2018  路  2Comments  路  Source: owen-it/laravel-auditing

| Q | A
| ----------------- | ---
| Bug? | no
| New Feature? | no
| Framework | Laravel
| Framework version | 5.6.29
| Package version | 8.0.3
| PHP version | 7.1.13

Actual Behaviour

Hi, i made all the setup and currently it is working the auditing, but i can't retrieve the relationship informations,if i try get the name of the user that did the change, all it returns is null. i am not sure if it is becouse i am using 2 schemas, one for auditing and one for the website itself. maybe i made some config wrong? but with my understanding of english i tried my best to follow the documentation

Expected Behaviour

Retrieve relationship from auditing through an Audit::with('user')->first();

Steps to Reproduce

two Schemas, one for audit and one for general tables, in the general tables, a user table with a primary key named id_usuario, in the migration and audit.php i added the $table->nullableMorphs('id_usuario'); and the 'user' => [ 'morph_prefix' => 'id_usuario', 'guards' => [ 'web', 'api', ], ],
i specified the connection too: 'drivers' => [ 'database' => [ 'table' => 'audits', 'connection' => 'scilogs', ], ],

the audit itself works, just the relationship returns null
here a dd of a audit:
image

help wanted V8

Most helpful comment

Don't know why i didn't try this before bothering you, but, Yeah, it worked, i made a belongsTo relationship on Audit Model and now is perfect, thank you.

All 2 comments

You could probably get it to work by eager loading the relation, otherwise you'll have to fetch it manually.

Don't know why i didn't try this before bothering you, but, Yeah, it worked, i made a belongsTo relationship on Audit Model and now is perfect, thank you.

Was this page helpful?
0 / 5 - 0 ratings