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

Fix for laravel backpack not saving user id #382

Closed
wants to merge 1 commit into from

Conversation

dilneiss
Copy link

With this fix it is still not working: #377

So i updated and tested and now is saving user id

@dilneiss
Copy link
Author

someone can approve this?

@dilneiss
Copy link
Author

is this project still active?

@duellsy
Copy link
Member

duellsy commented Feb 14, 2021

Apologies for not closing this off, however this was made available in 1.35.0

@duellsy duellsy closed this Feb 14, 2021
@Reinbier
Copy link
Contributor

Hi,

When using Laravel Backpack (and thus backpack_auth()) in combination with this project, the user Id still doesn't get inserted correctly in the database. I use the RevisionableTrait in combination with the package 'backpack/revise-operation'.

Digging deeper inside your code I discovered the fix mentioned in https://github.com/VentureCraft/revisionable/pull/377 was only added to the Revisionable.php class, and not in the RevisionableTrait, thus leaving user Id set to NULL in the revisions table.

I implemented the following temporary fix, using a custom Trait to inherit your trait and overwrite the getSystemUserId() method:

/**
 * Class RevisionableTrait extends that of Venturecraft\Revisionable
 */
trait MyRevisionableTrait
{
    use \Venturecraft\Revisionable\RevisionableTrait;

    /**
     * Attempt to find the user id of the currently logged in user
     * Supports Cartalyst Sentry/Sentinel based authentication, as well as stock Auth
     **/
    public function getSystemUserId()
    {
        try {
            if (class_exists($class = '\Cartalyst\Sentry\Facades\Laravel\Sentry')
                    || class_exists($class = '\Cartalyst\Sentinel\Laravel\Facades\Sentinel')) {
                return ($class::check()) ? $class::getUser()->id : null;
            } elseif (function_exists('backpack_auth') && backpack_auth()->check()) {
                return backpack_user()->id;
            } elseif (\Auth::check()) {
                return \Auth::user()->getAuthIdentifier();
            }
        } catch (\Exception $e) {
            return null;
        }

        return null;
    }
}

Here the code works correct! I just copied the code from the Revisionable-class that you already updated :-)

I hereby want to kindly ask you to implement this fix in your project.

Kind regards

@duellsy
Copy link
Member

duellsy commented Mar 28, 2021

Good catch, would you mind submitting a fresh PR to bring it to the trait?

@Reinbier
Copy link
Contributor

I just made a pull request, @duellsy. I also just discovered @dilneiss was referencing the same fix, lol!

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

Successfully merging this pull request may close these issues.

3 participants