Make a Shopify App with Laravel Framework
First we are going to install a fresh laravel app, then we will install a laravel-shopify package that will take care of most of the shopify integration work for us. Then we will create a new shopify app into shopify partner dashboard. Then we will configure our laravel app with shopify app credentials to they can connect to each other. Once all setup then we will install our app into a test store. The purpose of this story is to install the shopify app developed with laravel and install it to shopify test store.
I am going to use laravel valet in Macbook computer, but you can use use your own environement as long as you can setup a virtual host and support ssl.
In this tutorial I will assume you have some knowledge of laravel framework.
Open your terminal and go to your Webroot and install laravel
composer create-project — prefer-dist laravel/laravel jewel-plugin-shopifycd jewel-plugin-shopifycomposer require osiset/laravel-shopifyphp artisan vendor:publish — tag=shopify-configvalet secure jewel-plugin-shopify
Now we have the laravel app that can run at the address
https://jewel-plugin-shopify.test
Now we are going to create a new shopify app from shopify partner dashboard
Login to shopify partner dashboard, if you don’t have you can immediately create one, it’s completely free.
Once on the partner dashboard create a new App name jewel delivery app, app url to https://jewel-plugin-shopify.test and white listed delivery url to https://jewel-plugin-shopify.test/authenticate
Once you created the app copy the api keys and secret, this we will use in your laravel app into the .env file
we need to setup the values according to this file config/shopify-app.php
we just need to create this line
SHOPIFY_APP_NAME=”Jewel Delivery App”SHOPIFY_API_KEY=38db7d21889f........SHOPIFY_API_SECRET=shpss_17ac059a57e........SHOPIFY_API_SCOPES=read_products,write_products,read_customers,write_customers,read_orders,write_orders,read_shipping,write_shipping,read_checkouts,write_checkouts,read_locales,read_script_tags,write_script_tags,read_locations,read_themes,write_themes
You can check the all access list by visiting this url https://shopify.dev/docs/admin-api/access-scopes
Also make a mysql database name jewel-delivery and fill up the database fields into the .env file
Now we will create a route in web.php file
Route::get(‘/’, function () {return view(‘welcome’);})->middleware([‘auth.shopify’])->name(‘home’);
Now replace the welcome.blade.php code with this below code
@extends('shopify-app::layouts.default')@section('content')<!-- You are: (shop domain name) --><p>You are: {{ Auth::user()->name }}</p>@endsection@section('scripts')@parent<script type="text/javascript">var AppBridge = window['app-bridge'];var actions = AppBridge.actions;var TitleBar = actions.TitleBar;var Button = actions.Button;var Redirect = actions.Redirect;var titleBarOptions = {title: 'Welcome',};var myTitleBar = TitleBar.create(app, titleBarOptions);</script>@endsection
Now in the User.php model add these
use Osiset\ShopifyApp\Contracts\ShopModel as IShopModel;use Osiset\ShopifyApp\Traits\ShopModel;
Next, modify the class line to become:
class User extends Authenticatable implements IShopModel
Next, inside the class, add:
use ShopModel;
Once its configured then run the migration
php artisan vendor:publish — tag=shopify-migrations && php artisan migrate
Now install the app in a test store. If all goes well you should be able to see your home page the shop user name
Thats it, we just successfully setup and install a shopify app in shopify test store
Next we will continue implement the functionality of our newly developed app.