PHP code example of bogdanmosiets2006 / shop-package-3laba

1. Go to this page and download the library: Download bogdanmosiets2006/shop-package-3laba 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/ */

    

bogdanmosiets2006 / shop-package-3laba example snippets


// database/seeders/DatabaseSeeder.php
use Vendor\ShopPackage\Database\Seeders\ShopSeeder;

public function run(): void
{
    $this->call(ShopSeeder::class);
}

// Префикс web-маршрутов (по умолчанию: 'shop')
'route_prefix' => 'shop',

// Префикс API-маршрутов (по умолчанию: 'api/shop')
'api_prefix' => 'api/shop',

// Требуемая версия API для middleware
'api_version' => 1,

// Драйвер расчёта доставки: 'haversine' | 'nominatim' | 'openrouteservice'
'delivery' => [
    'driver' => 'haversine',
],

use Vendor\ShopPackage\Facades\CurrencyRate;
use Vendor\ShopPackage\Facades\DeliveryCalculator;

// Получить курс EUR к базовой валюте (USD)
$rate = CurrencyRate::getRate('EUR');

// Конвертировать 100 USD в EUR
$amount = CurrencyRate::convert(100, 'USD', 'EUR');

// Рассчитать доставку (Haversine — координаты "lat,lon")
$delivery = DeliveryCalculator::calculate('55.7558,37.6173', '59.9343,30.3351');
// ['distance_km' => 634.5, 'cost' => 317.25, 'driver' => 'haversine']

// Принудительно через Nominatim (адреса в произвольном виде)
$delivery = DeliveryCalculator::calculateByNominatim('Москва', 'Санкт-Петербург');

// Принудительно через OpenRouteService
$delivery = DeliveryCalculator::calculateByOpenRouteService('Москва', 'Казань');

// Для всего маршрута — версия из конфига
Route::get('/data', SomeController::class)->middleware(CheckApiVersion::class);

// Версия задана явно для конкретного маршрута
Route::get('/v2/data', SomeController::class)->middleware('check.api.version:2');

protected $routeMiddleware = [
    'check.api.version' => \Vendor\ShopPackage\Http\Middleware\CheckApiVersion::class,
];
bash
# Конфигурация
php artisan vendor:publish --tag=shop-config

# Миграции
php artisan vendor:publish --tag=shop-migrations
php artisan migrate

# Шаблоны страниц
php artisan vendor:publish --tag=shop-views

# Тесты
php artisan vendor:publish --tag=shop-tests
bash
php artisan db:seed