Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUID user_type and user_id store error #918

Open
aytsystems opened this issue Mar 29, 2024 · 3 comments
Open

UUID user_type and user_id store error #918

aytsystems opened this issue Mar 29, 2024 · 3 comments

Comments

@aytsystems
Copy link

aytsystems commented Mar 29, 2024

I use laravel 9 and I'm using UUID in all tables.
I'm having problems registering the user_id and user_type. The other fields are registered normally.
I`m using API with Sanctum Auth

I didnt found $table->nullableMorphs('owner') on my User migration.

Audit migration

  public function up()
  {
      $connection = config('audit.drivers.database.connection', config('database.default'));
      $table = config('audit.drivers.database.table', 'audits');

      Schema::connection($connection)->create($table, function (Blueprint $table) {

          $morphPrefix = config('audit.user.morph_prefix', 'user');

          $table->bigIncrements('id');
          $table->string($morphPrefix . '_type')->nullable();
          $table->uuid($morphPrefix . '_id')->nullable();
          $table->string('event');
          $table->string('auditable_type');
          $table->uuid('auditable_id');
          $table->text('old_values')->nullable();
          $table->text('new_values')->nullable();
          $table->text('url')->nullable();
          $table->ipAddress('ip_address')->nullable();
          $table->string('user_agent', 1023)->nullable();
          $table->string('tags')->nullable();
          $table->timestamps();

          $table->index([$morphPrefix . '_id', $morphPrefix . '_type']);
      });
  }
@aytsystems
Copy link
Author

In the file OwenIt\Auditing\Auditable;
on line 346 and 347 in the
$morphPrefix. '_id' and $morphPrefix . '_type'

I set the variables manually just for testing
$morphPrefix . '_id' => auth()->user()->id,
$morphPrefix . '_type' => 'App\Models\User',
And it worked!

then noticed that the functions $user->getAuthIdentifier() and $user->getMorphClass() it's not working for me.

@aldinokemal
Copy link

$user->getAuthIdentifier()
$user->getMorphClass()
you said that that function is no working.

Just wanna make sure, have you use HasUuids in your model?

@parallels999
Copy link

I set the variables manually just for testing

$morphPrefix . '_id' => auth()->user()->id,
$morphPrefix . '_type' => 'App\Models\User',

And it worked!
then noticed that the functions $user->getAuthIdentifier() and $user->getMorphClass() it's not working for me.

return Auth::guard($guard)->user();

User resolver returns auth()->user()
Illuminate/Contracts/Auth/Guard.php#L24-L26 user() returns Illuminate/Auth/Authenticatable.php
and Illuminate/Auth/Authenticatable.php has getAuthIdentifier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants