PHP code example of litvinjuan / laravel-shopify
1. Go to this page and download the library: Download litvinjuan/laravel-shopify library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
litvinjuan / laravel-shopify example snippets bash
php artisan vendor:publish --tag="laravel-shopify-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="laravel-shopify-config"
php
// laravel-shopify.php
// ...
'shop-model' => App\Models\Shop::class // or your namespace
// ...
php
// laravel-shopify.php
// ...
'user-model' => App\Models\User::class // or your namespace
// ...
php
class UserShopLoader implements ShopLoader
{
public function load(): ?ShopContract
{
if (! Auth::check()) {
return null;
}
return Auth::user()->shop;
}
}
php
// laravel-shopify.php
// ...
'shop-loader-class' => App\Loaders\MyCustomShopLoader::class // or your namespace
// ...
php
Route::post('/shopify/webhook', 'MyController@webhook')->middleware(['signed.shopify']);
php
Route::get('/shopify/app', 'ShopifyController@app')->middleware(['auth:shopify']);
php
Route::get('/redirect', 'ShopifyController@redirect');
Route::get('/callback', 'ShopifyController@callback');
php
public function redirect(Request $request)
{
$shopDomain = $request->input('shop');
return Shopify::redirect($user, $shopDomain);
}
php
public function callback(Request $request)
{
$shopDomain = $request->input('shop');
return Shopify::redirect($user, $shopDomain);
}
php
public function callback(Request $request)
{
$shopDomain = $request->input('shop');
return Shopify::redirect($user, $shopDomain, 'https://mysite.com/custom-callback', ['scope1', 'another-cool-scope']);
}
php
$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(...);
// ...