laravel-auditing icon indicating copy to clipboard operation
laravel-auditing copied to clipboard

Way to use the package without the use of Auth?

Open AlexLightning opened this issue 3 years ago • 3 comments
trafficstars

Q A
Bug? no
New Feature? yes
Framework Laravel
Framework version 9.0.2
Package version 13.0.3
PHP version 8.0.8

Actual Behaviour

I do not use Auth for users in my service. I see that the implementation of the UserResolver is this:

image

Is there any way to do something like:

$morphPrefix . '_id'   => $user ? $user->id : null,
$morphPrefix . '_type' => $user ? $user->type: null,

instead of

$morphPrefix . '_id'   => $user ? $user->getAuthIdentifier() : null,
$morphPrefix . '_type' => $user ? $user->getMorphClass() : null,

Expected Behaviour

Because I just want to use the model that I return in my resolver:

<?php
namespace App\Resolvers;

use Illuminate\Support\Facades\Request;
use App\DataServiceModels\User;

class UserResolver implements \OwenIt\Auditing\Contracts\UserResolver
{
    /**
     * {@inheritdoc}
     */
    public static function resolve()
    {
        $current_user = User::where(['user_id' => Request::get('user_id'), 'type' => Request::get('user_type')])->get();
        $current_user = count($current_user) > 0 ? $current_user[0] : null;

        return $current_user;
    }
}

Possible Solutions

Make that part configurable? Or is there any way that I can achieve what I am looking for?

Thanks!

AlexLightning avatar Jun 07 '22 14:06 AlexLightning

You can change everything on config, just read documentation

PaolaRuby avatar Jun 20 '22 23:06 PaolaRuby

I have read the documentation multiple times before opening this issue :) I was not able to find, or at least understand what I can use to achieve this... Could you please at least show me which part of the documentation might help me with this?

AlexLightning avatar Jun 22 '22 09:06 AlexLightning

Did you try adding getAuthIdentifier() on user model

public function getAuthIdentifier(){
    return $this->id;
}

erikn69 avatar Jun 22 '22 16:06 erikn69

Closed due to inactivity

erikn69 avatar Mar 07 '23 20:03 erikn69