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 Mar 17, 2020 · 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 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.