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

Improved documentation with Spatie\Permissions #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

juhasev
Copy link
Contributor

@juhasev juhasev commented Sep 3, 2019

No description provided.

Copy link
Contributor Author

@juhasev juhasev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load order should read 'CacheServiceProvider' as opposed to 'AppServiceProvider'

@juhasev
Copy link
Contributor Author

juhasev commented Sep 3, 2019

Also if user is using Redis as session store, the new CacheServiceProvider must be loaded before SessionServiceProvider.

@juhasev
Copy link
Contributor Author

juhasev commented Sep 3, 2019

The current example returns null from CLI as the config file driver.php doesn't even exist. Perhaps better alternative would be to set the $uuid variable simply to 'cli'.

@juhasev
Copy link
Contributor Author

juhasev commented Sep 3, 2019

Ended up going with Redis based caching for the domains. Join query is sort of expensive.

Cache::extend('redis_tenancy', function ($app) {

            if (PHP_SAPI === 'cli') {
                $uuid = 'cli';
            } else {

                $fqdn = request()->getHost();

                $uuid = Redis::get('domains:'.$fqdn);

                if ($uuid==0) {

                    $uuid = DB::table('hostnames')
                        ->select('websites.uuid')
                        ->join('websites', 'hostnames.website_id', '=', 'websites.id')
                        ->where('fqdn', $fqdn)
                        ->value('uuid');

                    Redis::set('domains:'.$fqdn, $uuid, 'ex', 60*60*24);
                }
            }

            return Cache::repository(new RedisStore(
                $app['redis'],
                $uuid,
                $app['config']['cache.stores.redis.connection']
            ));
        });

@ArlonAntonius
Copy link
Member

Feel like this should be moved to the docs regarding laravel-permissions 🤔

Copy link
Member

@ArlonAntonius ArlonAntonius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the one comment, perfect PR. Like I said in a comment, feel like this should be moved to the spatie/permissions tutorial we have, you could add a footnote/sidenote in the cache docs to refer to that specific section in the tutorial.

@@ -51,3 +51,26 @@ allows you to set a custom cache driver in `config/cache.php`:

> Make sure the CacheServiceProvider is registered in `config/app.php` or else your driver will
not be available for use.

If you are using Spatie\Permission package and receive error about driver `redis_tenancy` is not supported,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spatie/laravel-permission please :)

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.

2 participants