tenancy-docs/dist/docs/1.x/tenant-manager/index.html
2019-09-18 16:33:16 +02:00

467 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="Tenant Manager | stancl/tenancy — A Laravel multi-database tenancy package that respects your code.">
<meta property="og:site_name" content="stancl/tenancy documentation"/>
<meta property="og:title" content="Tenant Manager | stancl/tenancy documentation"/>
<meta property="og:description" content="Tenant Manager | stancl/tenancy — A Laravel multi-database tenancy package that respects your code."/>
<meta property="og:url" content="https://tenancy.samuelstancl.me/docs/1.x/tenant-manager"/>
<meta property="og:image" content="/assets/img/logo.png"/>
<meta property="og:type" content="website"/>
<meta name="twitter:image:alt" content="stancl/tenancy documentation">
<meta name="twitter:card" content="summary_large_image">
<title>Tenant Manager | stancl/tenancy documentation</title>
<link rel="home" href="https://tenancy.samuelstancl.me/docs">
<link rel="icon" href="/favicon.ico">
<!-- Insert analytics code here -->
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,300i,400,400i,700,700i,800,800i" rel="stylesheet">
<link rel="stylesheet" href="/assets/build/css/main.css?id=0e3d47a146ef55ad0760">
</head>
<body class="flex flex-col justify-between min-h-screen bg-grey-lightest text-grey-darkest leading-normal font-sans">
<header class="flex items-center shadow bg-white border-b h-24 mb-8 py-4" role="banner">
<div class="container flex items-center max-w-4xl mx-auto px-4 lg:px-8">
<div class="flex items-center">
<a href="/" title="stancl/tenancy documentation home" class="inline-flex items-center">
<h1 class="text-lg md:text-2xl text-blue-darkest font-semibold hover:text-blue-dark my-0 pr-4">stancl/tenancy documentation</h1>
</a>
</div>
<div class="flex flex-1 justify-end items-center text-right md:pl-10">
</div>
<div class="flex flex-1 justify-end items-center text-right md:pl-10">
<select id="versionSelect">
<option
value="/https://tenancy.samuelstancl.me/docs1.x"
selected
>
1.x
</option>
<option
value="/https://tenancy.samuelstancl.me/docs2.x"
>
2.x (beta)
</option>
</select>
</div>
</div>
<button class="flex justify-center items-center bg-blue border border-blue h-10 mr-4 px-5 rounded-full lg:hidden focus:outline-none"
onclick="navMenu.toggle()"
>
<svg id="js-nav-menu-show" xmlns="http://www.w3.org/2000/svg"
class="fill-current text-white h-9 w-4" viewBox="0 0 32 32"
>
<path d="M4,10h24c1.104,0,2-0.896,2-2s-0.896-2-2-2H4C2.896,6,2,6.896,2,8S2.896,10,4,10z M28,14H4c-1.104,0-2,0.896-2,2 s0.896,2,2,2h24c1.104,0,2-0.896,2-2S29.104,14,28,14z M28,22H4c-1.104,0-2,0.896-2,2s0.896,2,2,2h24c1.104,0,2-0.896,2-2 S29.104,22,28,22z"/>
</svg>
<svg id="js-nav-menu-hide" xmlns="http://www.w3.org/2000/svg"
class="hidden fill-current text-white h-9 w-4" viewBox="0 0 36 30"
>
<polygon points="32.8,4.4 28.6,0.2 18,10.8 7.4,0.2 3.2,4.4 13.8,15 3.2,25.6 7.4,29.8 18,19.2 28.6,29.8 32.8,25.6 22.2,15 "/>
</svg>
</button>
</header>
<main role="main" class="w-full flex-auto">
<section class="container max-w-4xl mx-auto px-6 md:px-8 py-4">
<div class="flex flex-col lg:flex-row">
<nav id="js-nav-menu" class="nav-menu hidden lg:block">
<ul class="list-reset my-0">
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/getting-started"
class="lvl0 nav-menu__item hover:text-blue"
>
Getting Started
</a>
<ul class="list-reset my-0">
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/installation"
class="lvl1 nav-menu__item hover:text-blue"
>
Installation
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/storage-drivers"
class="lvl1 nav-menu__item hover:text-blue"
>
Storage Drivers
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/difference-between-this-package-and-others"
class="lvl1 nav-menu__item hover:text-blue"
>
This Package vs Others
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/configuration"
class="lvl1 nav-menu__item hover:text-blue"
>
Configuration
</a>
</li>
</ul>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/usage"
class="lvl0 nav-menu__item hover:text-blue"
>
Usage
</a>
<ul class="list-reset my-0">
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/creating-tenants"
class="lvl1 nav-menu__item hover:text-blue"
>
Creating Tenants
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/tenant-routes"
class="lvl1 nav-menu__item hover:text-blue"
>
Tenant Routes
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/tenant-storage"
class="lvl1 nav-menu__item hover:text-blue"
>
Tenant Storage
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/tenant-manager"
class="lvl1 active font-semibold text-blue nav-menu__item hover:text-blue"
>
Tenant Manager
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/console-commands"
class="lvl1 nav-menu__item hover:text-blue"
>
Console Commands
</a>
</li>
</ul>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/digging-deeper"
class="lvl0 nav-menu__item hover:text-blue"
>
Digging Deeper
</a>
<ul class="list-reset my-0">
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/middleware-configuration"
class="lvl1 nav-menu__item hover:text-blue"
>
Middleware Configuration
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/custom-database-names"
class="lvl1 nav-menu__item hover:text-blue"
>
Custom Database Names
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/filesystem-tenancy"
class="lvl1 nav-menu__item hover:text-blue"
>
Filesystem Tenancy
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/jobs-queues"
class="lvl1 nav-menu__item hover:text-blue"
>
Jobs &amp; Queues
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/event-system"
class="lvl1 nav-menu__item hover:text-blue"
>
Event System
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/tenancy-initialization"
class="lvl1 nav-menu__item hover:text-blue"
>
Tenancy Initialization
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/application-testing"
class="lvl1 nav-menu__item hover:text-blue"
>
Application Testing
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/writing-storage-drivers"
class="lvl1 nav-menu__item hover:text-blue"
>
Writing Storage Drivers
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/development"
class="lvl1 nav-menu__item hover:text-blue"
>
Development
</a>
</li>
</ul>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/integrations"
class="lvl0 nav-menu__item hover:text-blue"
>
Integrations
</a>
<ul class="list-reset my-0">
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/telescope"
class="lvl1 nav-menu__item hover:text-blue"
>
Telescope
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/horizon"
class="lvl1 nav-menu__item hover:text-blue"
>
Horizon
</a>
</li>
</ul>
</li>
<li class="list-reset pl-4">
<p class="nav-menu__item text-grey-dark">Tips</p>
<ul class="list-reset my-0">
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/https-certificates"
class="lvl1 nav-menu__item hover:text-blue"
>
HTTPS Certificates
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/misc-tips"
class="lvl1 nav-menu__item hover:text-blue"
>
Misc
</a>
</li>
</ul>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/stay-updated"
class="lvl0 nav-menu__item hover:text-blue"
>
Stay Updated
</a>
</li>
<li class="list-reset pl-4">
<a href="https://tenancy.samuelstancl.me/docs/1.x/https://github.com/stancl/tenancy"
class="lvl0 nav-menu__item hover:text-blue"
>
GitHub
</a>
</li>
</ul>
</nav>
<div class="w-full lg:w-3/5 break-words pb-16 lg:pl-4" v-pre>
<h1 id="tenant-manager">Tenant Manager</h1>
<p>This page documents a couple of other <code>TenantManager</code> methods you may find useful.</p>
<h3>Finding tenant using UUID</h3>
<p><code>find()</code> is an alias for <code>getTenantById()</code>. You may use the second argument to specify the key(s) as a string/array.</p>
<pre><code class="language-php">&gt;&gt;&gt; tenant()-&gt;find('dbe0b330-1a6e-11e9-b4c3-354da4b4f339');
=&gt; [
"uuid" =&gt; "dbe0b330-1a6e-11e9-b4c3-354da4b4f339",
"domain" =&gt; "localhost",
"foo" =&gt; "bar",
]
&gt;&gt;&gt; tenant()-&gt;find('dbe0b330-1a6e-11e9-b4c3-354da4b4f339', 'foo');
=&gt; [
"foo" =&gt; "bar",
]
&gt;&gt;&gt; tenant()-&gt;getTenantById('dbe0b330-1a6e-11e9-b4c3-354da4b4f339', ['foo', 'domain']);
=&gt; [
"foo" =&gt; "bar",
"domain" =&gt; "localhost",
]</code></pre>
<h3>Getting tenant ID by domain</h3>
<pre><code class="language-php">&gt;&gt;&gt; tenant()-&gt;getTenantIdByDomain('localhost');
=&gt; "b3ce3f90-1a88-11e9-a6b0-038c6337ae50"
&gt;&gt;&gt; tenant()-&gt;getIdByDomain('localhost');
=&gt; "b3ce3f90-1a88-11e9-a6b0-038c6337ae50"</code></pre>
<h3>Finding tenant by domain</h3>
<p>You may use the second argument to specify the key(s) as a string/array.</p>
<pre><code class="language-php">&gt;&gt;&gt; tenant()-&gt;findByDomain('localhost');
=&gt; [
"uuid" =&gt; "b3ce3f90-1a88-11e9-a6b0-038c6337ae50",
"domain" =&gt; "localhost",
]</code></pre>
<h3>Accessing the array</h3>
<p>You can access the public array tenant of TenantManager like this:</p>
<pre><code class="language-php">tenancy()-&gt;tenant</code></pre>
<p>which is an array. If you want to get the value of a specific key from the array, you can use one of the helpers the key on the tenant array as an argument.</p>
<pre><code class="language-php">tenant('uuid'); // Does the same thing as tenant()-&gt;tenant['uuid']</code></pre>
<h3>Getting all tenants</h3>
<p>This method returns a collection of arrays.</p>
<pre><code class="language-php">&gt;&gt;&gt; tenant()-&gt;all();
=&gt; Illuminate\Support\Collection {#2980
all: [
[
"uuid" =&gt; "32e20780-1a88-11e9-a051-4b6489a7edac",
"domain" =&gt; "localhost",
],
[
"uuid" =&gt; "49670df0-1a87-11e9-b7ba-cf5353777957",
"domain" =&gt; "dev.localhost",
],
],
}
&gt;&gt;&gt; tenant()-&gt;all()-&gt;pluck('domain');
=&gt; Illuminate\Support\Collection {#2983
all: [
"localhost",
"dev.localhost",
],
}</code></pre>
<h3>Deleting a tenant</h3>
<pre><code class="language-php">&gt;&gt;&gt; tenant()-&gt;delete('dbe0b330-1a6e-11e9-b4c3-354da4b4f339');
=&gt; true
&gt;&gt;&gt; tenant()-&gt;delete(tenant()-&gt;getTenantIdByDomain('dev.localhost'));
=&gt; true
&gt;&gt;&gt; tenant()-&gt;delete(tenant()-&gt;findByDomain('localhost')['uuid']);
=&gt; true</code></pre>
<p>This doesn't delete the tenant's database. If you want to delete it, save the database name prior to deleting the tenant. You can get the database name using <code>getDatabaseName()</code></p>
<pre><code class="language-php">&gt;&gt;&gt; tenant()-&gt;getDatabaseName(tenant()-&gt;findByDomain('laravel.localhost'))
=&gt; "tenant67412a60-1c01-11e9-a9e9-f799baa56fd9"</code></pre> </div>
</div>
</section>
</main>
<script src="/assets/build/js/main.js?id=559633482baac87a89b5"></script>
<script>
const navMenu = {
toggle() {
const menu = document.getElementById('js-nav-menu');
menu.classList.toggle('hidden');
menu.classList.toggle('lg:block');
document.getElementById('js-nav-menu-hide').classList.toggle('hidden');
document.getElementById('js-nav-menu-show').classList.toggle('hidden');
},
}
</script>
<footer class="bg-white text-center text-sm mt-12 py-4" role="contentinfo">
<ul class="flex flex-col md:flex-row justify-center list-reset">
<li class="md:mr-2">
&copy; <a href="https://github.com/stancl" title="Samuel Štancl">Samuel Štancl</a> 2019.
</li>
<li>
Built with <a href="http://jigsaw.tighten.co" title="Jigsaw by Tighten">Jigsaw</a>
and <a href="https://tailwindcss.com" title="Tailwind CSS, a utility-first CSS framework">Tailwind CSS</a>.
</li>
</ul>
</footer>
<script>
document.getElementById('versionSelect').addEventListener('change', function () {
window.location = document.getElementById('versionSelect').value;
});
</script>
</body>
</html>