Skip to content

Improved documentation with Spatie\Permissions - #100

Open
juhasev wants to merge 1 commit into
tenancy:masterfrom
juhasev:patch-1
Open

Improved documentation with Spatie\Permissions#100
juhasev wants to merge 1 commit into
tenancy:masterfrom
juhasev:patch-1

Conversation

@juhasev

Copy link
Copy Markdown
Contributor

No description provided.

@juhasevjuhasev left a comment

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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

@juhasev

juhasev commented Sep 3, 2019

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

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

@ArlonAntoniusArlonAntonius left a comment

Copy link
Copy Markdown
Member

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.

Comment threaddocs/hyn/5.4/cache.md
> 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
Copy Markdown
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 freeto 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

@juhasev@ArlonAntonius