Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Namespacing Your App

Tyler King edited this page Aug 31, 2018 · 5 revisions

Information

This package comes with an optional method for namespacing your app. Meaning, you can run multiple apps on the same database instance; one shop, can be installed onto that database many times for different apps.

All shops when created get assigned a namespace through an Eloquent observer. By default, the namespace is null.

Its a simple namespace column on the shops table.

Setup

To create a namespace for an app, you simply need to modify your configuration. As per config/shopify-app.php:

    /*
    |--------------------------------------------------------------------------
    | Namespace
    |--------------------------------------------------------------------------
    |
    | This option allows you to set a namespace.
    | Useful for multiple apps using the same database instance.
    | Meaning, one shop can be part of many apps on the same database.
    |
    */

    'namespace' => env('SHOPIFY_APP_NAMESPACE', null),

You can simply replace this value with a string, or add SHOPIFY_APP_NAMESPACE=xxxxx to your environment file.

Finding All Shop Instances

By default, all queries on the database for the app are scoped to the current namespace for the shop. If you'd like to check all instances across all namespaces for a shop, simply remove the global scope on the call, example:

use OhMyBrew\ShopifyApp\Models\Shop;
use OhMyBrew\ShopifyApp\Namespaces\NamespaceScope;

// ...

$shopInstances = Shop::withoutGlobalScope(NamespaceScope::class)->where('shopify_domain', 'example.myshopify.com')->get();

Now, if example.myshopify.com is listed in the shops table more than once in different namespaces, you will be able to grab all those records.

Welcome to the wiki!

Please see the homepage for a list of relevant pages.

Clone this wiki locally