gnikyt / laravel-shopify

A full-featured Laravel package for aiding in Shopify App development
MIT License
1.24k stars 374 forks source link

Change model instead of users? #1154

Closed nam-co closed 2 years ago

nam-co commented 2 years ago

Hi @osiset I was wondering if it's possible to use another model instead of users? in a multiple staff scenario, where users belong to a company model, and the company is the one that needs access.

Also, (not important) for just 'read_products,read_product_listings' are all the migrations tables necessary ?

Appreciate any guidance, thanks for the work you put into the package

CetoBasilius commented 2 years ago

@nam-co Yes you can, you need to change your shop_auth_provider to shops and add your new shop provider to config/auth.php like so:

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        'shops' => [
            'driver' => 'eloquent',
            'model' => App\Models\Shop::class,
        ],
    ],

Make the Shop model, copy the user class and make it implement the same stuff and same ids, you'll need manual migrations, and change everything that references user to shop. Calling Auth::user() can return a shop or a user, depending on your context

Kyon147 commented 2 years ago

Decent solution provided so closing ticket.

nam-co commented 2 years ago

@CetoBasilius Sorry about this, I didn't see the answer before, appreciate the help Im going to give it a try, thank you

nam-co commented 2 years ago

@CetoBasilius @osiset sorry about this, but is there any way to include an extra field to be saved on the DB, for example biz_id, user_id or whatever_id?

Kyon147 commented 2 years ago

@nam-co just add it to your migrations when you create the shop table, you can just add whatever id you want when you create the table. Then in your user class, just create a relationship to the Shop table so you can access it via eloquent if you like.