PHPackages                             litvinjuan/laravel-shopify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. litvinjuan/laravel-shopify

ActiveLibrary[API Development](/categories/api)

litvinjuan/laravel-shopify
==========================

Connect your Laravel application to the Shopify API

1.0.6(4y ago)22.0k1MITPHPPHP ^7.4CI failing

Since Sep 23Pushed 4y ago2 watchersCompare

[ Source](https://github.com/litvinjuan/laravel-shopify)[ Packagist](https://packagist.org/packages/litvinjuan/laravel-shopify)[ Docs](https://github.com/litvinjuan/laravel-shopify)[ RSS](/packages/litvinjuan-laravel-shopify/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (7)Versions (12)Used By (0)

Connect your Laravel application to the Shopify API
===================================================

[](#connect-your-laravel-application-to-the-shopify-api)

[![Latest Version on Packagist](https://camo.githubusercontent.com/767f7ed584a869e62062ab52897ce818c4ed00d4b69174acc308c536255e6e99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c697476696e6a75616e2f6c61726176656c2d73686f706966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/litvinjuan/laravel-shopify)[![GitHub Tests Action Status](https://camo.githubusercontent.com/25c195315cdb999c3286e340a15a615471fc3e05eb719b23b84b2413ac6d234e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c697476696e6a75616e2f6c61726176656c2d73686f706966792f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/litvinjuan/laravel-shopify/actions?query=workflow%3Arun-tests+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/281aa515bd09c8bbc798e50d9a86bb09b9b828096859f19b1c6388b70167bb70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c697476696e6a75616e2f6c61726176656c2d73686f706966792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/litvinjuan/laravel-shopify)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require litvinjuan/laravel-shopify
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="laravel-shopify-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-shopify-config"
```

Setup
-----

[](#setup)

The package comes with a default Shop model that you can use. However, if you want to add extra properties or relationships, you'll need to create your own Shop model that implements the `ShopContract` interface and uses the `ShopTrait` trait.

```
class Shop extends Model implements ShopContract
{
    use ShopTrait;

    // Your relationships, properties, etc.
}
```

**Note: Remember to also modify the migration before running it to add any additional columns you may need**

Then, you have to add your shop model to the package configuration. Publish the configuration if you haven't (using the command in the `Installation` section) and change the `shop-model` value to your own model:

```
// laravel-shopify.php
// ...

'shop-model' => App\Models\Shop::class // or your namespace

// ...
```

The next step to set up our Shop owner, which is the model that's related to your shop. Right now, we only support the user as the owner, so go into your User model and add the following interface:

```
class User extends Authenticatable implements ShopifyOwner
{
    // ...
}
```

Now, there's two ways in which you can relate your users and shops.
If you want each user to only have one shop, then you should the `HasShop` trait. If you want each user to own multiple shops, meaning that one user has access to many shops, use the `HasShops` trait.

```
class User extends Authenticatable implements ShopifyOwner
{
    use HasShop; // one shop per user
    use HasShops; // multiple shops per user
}
```

**Note: only include one trait in your model**

Once your user model is set up, go into the configuration file once again and change the `user-model` value to your own model

```
// laravel-shopify.php
// ...

'user-model' => App\Models\User::class // or your namespace

// ...
```

The last step is to implement the `ShopLoader`. This is a class that will tell shopify how to determine which shop to use during requests. Below is an example of a ShopLoader that works for a user that only has one shop, and simply tells shopify to use the shop of the current authenticated user:

```
class UserShopLoader implements ShopLoader
{
    public function load(): ?ShopContract
    {
        if (! Auth::check()) {
            return null;
        }

        return Auth::user()->shop;
    }
}
```

Once you've implemented your own ShopLoader, or used the own provided above, you'll need to add it to the shopify configuration file:

```
// laravel-shopify.php
// ...

'shop-loader-class' => App\Loaders\MyCustomShopLoader::class // or your namespace

// ...
```

Lastly, you'll need to create an App in your Shopify Developer account, and set up the following variables in your `.env` file:

`SHOPIFY_API_KEY=` This is your app's api key. You can find it in your app dashboard
`SHOPIFY_API_SECRET=` This is your app's api secret. You can find it in your app dashboard
`SHOPIFY_API_SCOPES=` If no scopes are provided during an authentication request, shopify will use these.
`SHOPIFY_API_CALLBACK_URL=` Callback url to use after the user has installed the app on shopify. Remember to whitelist this URL in your app dashboard.

Usage
-----

[](#usage)

This package adds a few things to your laravel application.

First, you have a new middleware `signed.shopify`, which verifies that the request is coming from shopify and has a valid signature. Include this middleware in any webhook routes or other requests where you want to verify that the request came from Shopify.

```
Route::post('/shopify/webhook', 'MyController@webhook')->middleware(['signed.shopify']);
```

There's also a new Shopify authentication guard, which allows you to authenticate a user when they are viewing your app within the Shopify Admin Panel. You should use this auth guard for any routes that the user may access from within the Shopify Admin Panel, and not through your own website.

```
Route::get('/shopify/app', 'ShopifyController@app')->middleware(['auth:shopify']);
```

### Authentication

[](#authentication)

To authenticate your users in Shopify, you'll need to add two routes: one to redirect the user to Shopify's Oauth screen, and one for the callback from that screen:

```
Route::get('/redirect', 'ShopifyController@redirect');
Route::get('/callback', 'ShopifyController@callback');
```

In your redirect route, you'll need to receive a shop domain parameter for the Shopify store your user wants to connect to. Then, simply redirect them with the following:

```
public function redirect(Request $request)
{
    $shopDomain = $request->input('shop');
    return Shopify::redirect($user, $shopDomain);
}
```

After the user accepts the scopes and installs the app on their Shopify store, they'll be redirected back to your callback url. The last step, is to configure the callback to generate the necessary access token for the shop:

```
public function callback(Request $request)
{
    $shopDomain = $request->input('shop');
    return Shopify::redirect($user, $shopDomain);
}
```

You can also pass a different callback url or scopes as the third and fourth arguments to the redirect method

```
public function callback(Request $request)
{
    $shopDomain = $request->input('shop');
    return Shopify::redirect($user, $shopDomain, 'https://mysite.com/custom-callback', ['scope1', 'another-cool-scope']);
}
```

To interact with the Shopify Api, simply call the api() method in the shop you want to use, and hit the endpoint you want to use

```
$response = $shop->api()->get("/admin/api/2020-07/products.json");
$response = $shop->api()->post("/admin/api/2020-07/webhooks.json", [ /* ... payload ... */ ]);
$response = $shop->api()->put(...);
$response = $shop->api()->delete(...);
// ...
```

### Shopify Facade

[](#shopify-facade)

The package makes a Shopify Facade available that has a few useful methods.

```
Shopify::redirect               // First step of the Shopify authentication
Shopify::callback               // Last step of the Shopify authentication
Shopify::getShop                // Get the current shop. For routes viewed from the Shopigy Admin panel, this will be the current Shop. For routes within your own domain, this will be the one inferred from the ShopLoader you set in your config file
Shopify::setShop                // Manually set the current shop
Shopify::forget                 // Forget the current shop
Shopify::hasShop                // Returns true if there is a current shop set
Shopify::isValidHmac            // Validates the Shopify hmac signature for the current request
Shopify::assertShopExists       // Throws an exception if the Shopify store domain isn't found in the database
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Juan Litvin](https://github.com/litvinjuan)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Recently: every ~87 days

Total

11

Last Release

1698d ago

Major Versions

0.1.3 → 1.0.02020-09-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/caac9d056df003d8d88cb3e8540834ecfc31c90e08c4ccd67a38e869742e45ee?d=identicon)[litvinjuan](/maintainers/litvinjuan)

---

Top Contributors

[![litvinjuan](https://avatars.githubusercontent.com/u/42967171?v=4)](https://github.com/litvinjuan "litvinjuan (21 commits)")

---

Tags

laravel-shopifylitvinjuan

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/litvinjuan-laravel-shopify/health.svg)

```
[![Health](https://phpackages.com/badges/litvinjuan-laravel-shopify/health.svg)](https://phpackages.com/packages/litvinjuan-laravel-shopify)
```

###  Alternatives

[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)[esign/laravel-conversions-api

A laravel wrapper package around the Facebook Conversions API

69145.4k](/packages/esign-laravel-conversions-api)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
