Skip to content

Namespacing Your App

Luke Walsh edited this page Dec 18, 2022 · 1 revision

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 replace this value with a string directly, 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, you will need to remove the global scope on the query call, example:

use App\User;
use Osiset\ShopifyApp\Storage\Scopes\Namespacing;

// ...

$shopInstances = User::withoutGlobalScope(Namespacing::class)->where('name', '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.