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

Can't cache config #213

Closed
bradleybensmith opened this issue Mar 17, 2017 · 5 comments
Closed

Can't cache config #213

bradleybensmith opened this issue Mar 17, 2017 · 5 comments
Labels
bug Issue, error or unexpected behavior enhancement An improvement or new feature

Comments

@bradleybensmith
Copy link

bradleybensmith commented Mar 17, 2017

The framework will fail to boot when you cache the config with the new resolver closure:

...
  'user' => [
        'model'    => App\User::class,
        'resolver' => function () {
            return Auth::check() ? Auth::user()->getAuthIdentifier() : null;
        },
    ],
...

compiles to:

...
    'user' => 
    array (
      'model' => 'App\\User',
      'resolver' => 
      Closure::__set_state(array(
      )),
    ),
...
@quetzyg
Copy link
Contributor

quetzyg commented Mar 17, 2017

Hello @bram1028,

Yeah, a Closure in a config can't be cached, the same way that a Closure in a route. It's the price to pay for flexibility, I guess.

If you have an idea on how to overcome this issue, feel free to discuss.

I'll close this for now, though.

@quetzyg quetzyg closed this as completed Mar 17, 2017
@bradleybensmith
Copy link
Author

A static method on the user model?

@quetzyg quetzyg added bug Issue, error or unexpected behavior enhancement An improvement or new feature labels Mar 18, 2017
@quetzyg quetzyg reopened this Mar 18, 2017
@quetzyg quetzyg mentioned this issue Mar 18, 2017
@quetzyg
Copy link
Contributor

quetzyg commented Mar 18, 2017

The documentation will be updated shortly, but meanwhile here's what you have to do:

Update the resolver configuration to use a FQCN instead of a callable:

return [
    'user' = [
        'resolver' => App\User::class,
    ],
];

Implement the OwenIt\Auditing\Contracts\UserResolver interface on a class (User model, for instance):

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
use OwenIt\Auditing\Contracts\UserResolver;

class User extends Model implements AuditableContract, UserResolver
{
    use Auditable;

    /**
     * {@inheritdoc}
     */
    public static function resolveId()
    {
        return Auth::check() ? Auth::user()->getAuthIdentifier() : null;
    }

    // ...
}

@bradleybensmith
Copy link
Author

Well, I know that will work great, but I'm having some other trouble with config::cache now. It's not seeing the changes to the audit config and is still caching the old closure. Changes to other config files are being cached fine.

Thank you for this change!

@bradleybensmith
Copy link
Author

Found it! I didn't catch the filename change with v4...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue, error or unexpected behavior enhancement An improvement or new feature
Projects
None yet
Development

No branches or pull requests

2 participants