Overriding and Extending - aledelgo/laravel-shopify GitHub Wiki
Controllers & Routes
Because our provider is loaded before the app providers, you're free to use your routes/web.php to override routes.
To override the homepage route to point to your controller you can add the following to routes/web.php, example:
# Assumes you have a controller called "HomeController" (App\Http\Controllers\HomeController)
Route::get(
'/',
'HomeController@index'
)->middleware(['auth.shop', 'billable'])->name('home');
/ will now point to your own controller HomeController. Now, you can add your own methods/views. Keep in mind, to extend the base layout as it contains all ESDK setup, example: @extends('shopify-app::layouts.default').
New Routes
When defining your own routes, be sure to always have the route behind auth.shop as this will confirm the shop's session is valid before entering the controller.
If you wish to gate an area to paid shops only, also add billable middleware.
Views
If you wish to simply change a view in this package, such as the layout file...
Laravel will look for views in resources/views/vendor/shopify-app. To override the layout view you would create resources/views/vendor/shopify-app/layouts/default.blade.php.
Models
You can create Shop.php in App folder and extend the package's model.
<?php
namespace App;
use OhMyBrew\ShopifyApp\Models\Shop as BaseShop;
class Shop extends BaseShop
{
protected $table = 'shops';
// Your extensions or changes
}
You may also simply use the trait such as:
<?php
use OhMyBrew\ShopifyApp\Traits\ShopModelTrait;
class Shop
{
use ShopModelTrait;
// Your extensions or changes here
}
But beware, you must also copy over the model properties from OhMyBrew\ShopifyApp\Models\Shop for Eloquent to properly work with the model.
Important: In either case, you should open config/shopify-app.php and change shop_model to point to your own shop model, or set the path to the SHOPIFY_SHOP_MODEL environment variable.
Example:
'shop_model' => '\App\Shop' // or env('SHOPIFY_SHOP_MODEL') and change .env to point to it