Ecom Api

Ecom API Packages

Basic Information

  • name: "toolstation/ecom-api"
    • Purpose: Identifies the name of the package or project. This name is used by Composer and other tools to refer to this specific project.
  • description: "Toolstation ECOM API"
    • Purpose: Provides a brief overview of what the project is about, useful for documentation and when searching for the package.
  • version: "1.25.6"
    • Purpose: Specifies the version of the project. This helps in managing different releases and dependencies.
  • type: "project"
    • Purpose: Indicates that this is a full project rather than a library or component. This is useful for understanding how the package is intended to be used.

Dependencies

Lists the packages needed for the project to run correctly .

Package NameOverview
"appstract/laravel-opcache": "^4.0"Adds support for PHP's OPCache extension in Laravel, improving performance by caching PHP bytecode.
"arquivei/laravel-prometheus-exporter: "^2.0"Integrates Prometheus metrics with Laravel applications, enabling monitoring and performance tracking.
"fideloper/proxy": "^4.4"Handles proxy headers to ensure Laravel correctly interprets the client's IP address and other information when behind a proxy.
"fruitcake/laravel-cors": "^2.0"is a Laravel package designed to handle Cross-Origin Resource Sharing (CORS) in your Laravel application.
"laravel/scout": "^8.6"is an official Laravel package for full-text search.
"laravel/telescope": "^4.4"is debugging assistant for Laravel applications.
"simplesoftwareio/simple-qrcode": "~4"is a Laravel package used for generating QR codes in your Laravel applications.
"singlestoredb/singlestoredb-laravel": "^1.5",SingleStoreDB (formerly known as MemSQL) is a distributed SQL database designed for real-time analytics and high-performance transactional workloads
"geoip2/geoip2": "^2.13",GeoIP2 is an open source geolocation library for PHP. It provides IP-based geolocation services, allowing you to determine the location of website visitors based on their IP addresses.
""giggsey/libphonenumber-for-php": "^8.12",Libphonenumber for PHP is a library for parsing, formatting, and validating phone numbers in PHP. It provides functionality to work with phone numbers in various formats and regions.
"google/cloud": "^0.222.0",Google Cloud Platform PHP API Client. It provides access to various Google Cloud services and APIs, allowing you to interact with Google Cloud resources programmatically.
"guzzlehttp/guzzle": "^7.0.1",Guzzle is an HTTP client library for PHP. It simplifies sending HTTP requests and handling responses, making it easier to interact with web services and APIs.
"spiral/roadrunner-http": "^2.0",This package is part of the RoadRunner ecosystem, providing HTTP support for the RoadRunner application server.
""spiral/roadrunner-metrics": "^2.0",This package provides metrics and monitoring capabilities for the RoadRunner application server, allowing you to collect and analyze metrics related to the server's performance.
"toolstation/*",These are various packages from the toolstation namespace, all marked with @dev.

appstract/laravel-opcache

  • Package Version in ECOM-API : "4.0"

The appstract/laravel-opcache package is a Laravel package designed to manage the OPcache settings of your PHP environment. OPcache is a caching engine built into PHP that improves performance by storing precompiled script bytecode in shared memory, which eliminates the need for PHP to load and parse scripts on each request.

Installation

composer require appstract/laravel-opcache

php artisan vendor:publish --provider="Appstract\Opcache\OpcacheServiceProvider" --tag="config"

Configuration

  • Config file
    Open the config/opcache.php file. Here, you can configure various options for OPcache.

Note

This is not configured in this project.

Configuration Breakdown in ECOM-API Project

return [
    'url' => env('OPCACHE_URL', config('app.url')),
    'prefix' => 'opcache-api',
    'verify' => true,
    'headers' => [],
    'directories' => [
        base_path('app'),
        base_path('bootstrap'),
       ...........................
    ],
    'exclude' => [
        'test',
        'Test',
        'tests',
       .......
    ],
];
  1. url:
    Purpose: This defines the base URL for the OPcache API.
    Configuration: It uses the OPCACHE_URL environment variable. If OPCACHE_URL is not set, it defaults to the application's base URL (config('app.url')). This URL is where the OPcache interface will be accessible.
  2. Prefix: The routes for the OPcache API will be prefixed with opcache-api. For example, the API might be accessible at yourapp.com/opcache-api.
  3. directories This specifies which directories should be included in the OPcache analysis.
  4. exclude This defines a list of directories or files that should be excluded from the OPcache analysis.

arquivei/laravel-prometheus-exporter

  • Package Version in ECOM-API : "2.0"

The arquivei/laravel-prometheus-exporter package is designed to integrate Prometheus monitoring with Laravel applications. Prometheus is an open-source monitoring and alerting toolkit widely used for collecting and querying metrics. This package allows you to expose metrics from your Laravel application in a format that Prometheus can scrape and monitor.

Installation

composer require superbalist/laravel-prometheus-exporter

Key Features and Uses

  1. Expose Metrics for Prometheus:
  • The package enables your Laravel application to expose various metrics about its performance, such as request counts, response times, and other custom metrics. Prometheus can scrape these metrics at regular intervals.
  1. Integration with Laravel:
  • It provides a simple integration for Laravel, making it easier to expose metrics from your application without extensive custom coding.
  1. Custom Metrics:
  • You can define custom metrics specific to your application, such as tracking the number of times certain events occur or monitoring the performance of specific parts of your application.
  1. Dashboard and Alerts:
  • With Prometheus collecting metrics from your Laravel application, you can use tools like Grafana to visualize these metrics in dashboards and set up alerts based on certain thresholds or conditions.

Configure the Package

Open the config/prometheus.php file and configure the metrics you want to expose. For example, you might want to add custom metrics or adjust the default settings:

return [
    'enabled' => env('PROMETHEUS_ENABLED', true),
    'prefix' => 'laravel',
    'routes' => [
        'prometheus' => [
            'uri' => 'prometheus',
            'middleware' => ['web'],
        ],
    ],
];

Configuration Breakdown in ECOM-API Project : Go to directory config/prometheus.php

fideloperproxy

  • Package Version in ECOM-API : "4.4"

The fideloper/proxy package is a Laravel package that helps handle HTTP proxies correctly. It's particularly useful when your Laravel application is behind a proxy server or load balancer, which can modify HTTP headers in ways that affect the application’s ability to detect the client’s real IP address and other important information.

Installation

composer require fideloper/proxy

Key Features and Uses

  1. Correct Client IP Detection:
  • When your application is behind a proxy or load balancer, it’s essential to obtain the client’s real IP address for accurate logging, security, and other purposes. fideloper/proxy ensures that Laravel properly retrieves the client’s real IP address from headers like X-Forwarded-For.
  1. Secure Headers:
  • The package helps Laravel interpret headers correctly, which is crucial for applications using proxies, load balancers, or CDN services. This includes handling headers that indicate the original request’s scheme (HTTP or HTTPS) and the host.
  1. Trusted Proxies Configuration:
  • You can configure which proxies or load balancers are trusted to set these headers. This is crucial to prevent spoofing of IP addresses and other header values.

Configuration

  1. Update config/trustedproxy.php Open the config/trustedproxy.php file. You will see configuration options to define trusted proxies and handling of headers.
return [
    'proxies' => '*', // You can specify IP addresses or CIDR notation to define trusted proxies.
    'headers' => [
        Illuminate\Http\Request::HEADER_X_FORWARDED_FOR     |
        Illuminate\Http\Request::HEADER_X_FORWARDED_PORT    |
        Illuminate\Http\Request::HEADER_X_FORWARDED_PROTO   |
        Illuminate\Http\Request::HEADER_X_FORWARDED_HOST,
    ],
];
  1. Update Middleware Ensure that the \Fideloper\Proxy\TrustProxies::class middleware is registered in your App\Http\Kernel class. It is typically added to the $middleware array in app/Http/Kernel.php:
protected $middleware = [
    \Fideloper\Proxy\TrustProxies::class,
    // other middleware...
];

fruitcakelaravel-cors

  • Package Version in ECOM-API : "2.0"

The fruitcake/laravel-cors package provides a simple way to manage CORS headers and policies in a Laravel application. It integrates seamlessly with Laravel's middleware system, allowing you to configure CORS settings globally or on a per-route basis.

Installation

composer require fruitcake/laravel-cors

Configuration

After installing the package, you need to configure CORS settings. In Laravel, this is typically done in the config/cors.php file.

To publish the configuration file, use the following Artisan command:

php artisan vendor:publish --provider="Fruitcake\Cors\CorsServiceProvider"

  • Configure config/cors.php:
  1. Service Provider For Laravel versions 5.5 and later, the package will automatically register its service provider due to Laravel's package auto-discovery feature. For older versions of Laravel, you may need to manually register the service provider in config/app.php:
'providers' => [
    // Other Service Providers

    Fruitcake\Cors\CorsServiceProvider::class,
],

In the config/cors.php file, you can set various options to control how CORS is handled.

return [
    'paths' => ['api/*'],
    
    'allowed_methods' => ['*'],
    
    'allowed_origins' => ['*'],
    
    'allowed_origins_patterns' => [],
    
    'allowed_headers' => ['*'],
    
    'exposed_headers' => [],
    
    'max_age' => 0,
    
    'supports_credentials' => true,
];

Middleware Usage

The fruitcake/laravel-cors package automatically handles CORS for routes specified in the configuration. However, if you need more control or are using an older version of Laravel, you can manually add the middleware in your app/Http/Kernel.php:

Note

This package is not available now.

laravelscout

  • Package Version in ECOM-API : "8.6"

Laravel Scout abstracts the complexities of integrating with various search engines by providing a consistent and user-friendly API. It allows you to perform full-text search on your models and sync search indexes easily.

Installation

composer require laravel/scout

Key Features

  • Full-Text Search: Adds full-text search capabilities to your Eloquent models.
  • Simple API: Provides a straightforward API for indexing and searching models.
  • Search Engines: Supports various search engines, including Algolia and Elasticsearch.
  • Automatic Syncing: Keeps search indexes synchronized with your database.

Configuration Breakdown in ECOM-API Project

  • it is currently disable in ECOM application 'driver' => env('DISABLE_SCOUT', false) ? null : env('SCOUT_DRIVER', 'algolia'),
  • Algolia Configuration:

If you're using Algolia, you'll configure your Algolia credentials here. in config/scout.phpExample

 'algolia' => [
 'id' => env('ALGOLIA_ID'),
 'secret' => env('ALGOLIA_SECRET'),
],

Scout in Different Directories in ECOM

  • vendor/toolstation/products/Models/Product.php
class Product extends Model
{
    use HasImage;
    use HasTranslatedFields;
    use Searchable;
    }

Configuration

  1. Configure Driver: In the config/scout.php file, you’ll specify which search engine you want to use. Laravel Scout supports multiple drivers, such as Algolia and Elasticsearch. You need to configure the driver and its related settings.

Note:

Ensure you have the necessary credentials in your .env file:

SCOUT_DRIVER=algolia
ALGOLIA_ID=your-algolia-id
ALGOLIA_SECRET=your-algolia-secret
  1. Add Searchable Trait: To make an Eloquent model searchable, you need to use the Searchable trait provided by Scout. For example:
      use Laravel\Scout\Searchable;
    
      class Post extends Model
      {
      use Searchable;
    
      // Define any custom logic or settings...
      }
    
  2. Configure Index Settings: You can configure your index settings using the searchable method on your model. For instance, you can define which fields should be indexed or customize how indexing is handled.
      public function toSearchableArray()
      {
       $array = $this->toArray();
    
       // Customize the data to be indexed...
       return $array;
      }
    

Note: Once your models are indexed, you can perform searches using the search method:

laraveltelescope

  • Package Version in ECOM-API : "4.4"

Laravel Telescope is a powerful debugging assistant for Laravel applications. It provides a deep dive into your application’s inner workings, offering insight into requests, exceptions, database queries, queued jobs, and more. Telescope is particularly useful for developers who need to monitor and debug their applications during development.

Installation

composer require laravel/telescope

Configuration You can configure Telescope in config/telescope.php. Some notable configuration options include:

watchers: Enable or disable specific watchers. You can turn on or off monitoring for requests, exceptions, queries, etc.

'watchers' => [
    \Laravel\Telescope\Watchers\RequestWatcher::class => env('TELESCOPE_REQUEST_WATCHER', true),
    \Laravel\Telescope\Watchers\ExceptionWatcher::class => env('TELESCOPE_EXCEPTION_WATCHER', true),
    // Other watchers
],

Configuration Breakdown in ECOM-API Project

'only_paths' => [
        // 'api/*'
    ],

    'ignore_paths' => [
        'nova-api*',
    ],

    'ignore_commands' => [
        //
    ],
  • only_paths:
    • Purpose: Specifies which URI paths Telescope should monitor.
    • Configuration: The default is empty, meaning Telescope will monitor all paths. You can uncomment and customize this array if you want to restrict monitoring to specific paths.
  • ignore_paths:
    • Purpose: Lists URI paths that Telescope should ignore.
    • Configuration: nova-api* means Telescope will ignore any routes that start with nova-api, useful if you're using Laravel Nova and want to exclude its routes from Telescope’s monitoring.
  • ignore_commands:
    • Purpose: Lists Artisan commands that Telescope should ignore.
    • Configuration: The default is empty, meaning all commands are monitored. You can add commands to this array if you want to exclude specific Artisan commands from monitoring.

Summary This configuration file allows you to customize how Laravel Telescope integrates with your application. You can control its accessibility, storage options, which data is monitored, and how data is handled. Adjusting these settings allows you to tailor Telescope’s functionality to better suit your development and monitoring needs.

simplesoftwareiosimple-qrcode

  • Package Version in ECOM-API : "~4"

The simplesoftwareio/simple-qrcode package is a Laravel package used for generating QR codes in your Laravel applications. It's a simple and flexible library that leverages the simple-qrcode package to create QR codes with ease.

Installation

composer require simplesoftwareio/simple-qrcode

Key FeaturesQR Code Generation: Easily generate QR codes from strings, URLs, or any text data. Customizable: Customize QR codes with different settings like size, color, and encoding. Integration: Seamlessly integrates with Laravel, allowing you to use it in controllers, views, and more.

Configuration In the config/qrcode.php file, you can set global options for QR code generation:

singlestoredbsinglestoredb-laravel

  • Package Version in ECOM-API : "1.5"

The singlestoredb/singlestoredb-laravel package is a Laravel-specific integration for SingleStoreDB (formerly known as MemSQL). SingleStoreDB is a high-performance, distributed SQL database that combines transactional and analytical workloads. The Laravel package provides tools and features to seamlessly integrate SingleStoreDB with Laravel applications.

Configure the Database Connection: Update your config/database.php file to include SingleStoreDB configuration. You need to add a new connection entry under the connections array.

Example

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

    'singlestoredb' => [
        'driver' => 'mysql',
        'host' => env('SINGLESTOREDB_HOST', '127.0.0.1'),
        'port' => env('SINGLESTOREDB_PORT', '3306'),
        'database' => env('SINGLESTOREDB_DATABASE', 'forge'),
        'username' => env('SINGLESTOREDB_USERNAME', 'forge'),
        'password' => env('SINGLESTOREDB_PASSWORD', ''),
        'unix_socket' => env('SINGLESTOREDB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],
],

Configurations used in ECOM Application

<?php

use Illuminate\Support\Str;

if (! function_exists('get_db_name')) {
    function get_db_name($db)
    {
        return strpos($db, '.sqlite') ? database_path('dbs/'.$db) : $db;
    }
}

The get_db_name function is used to modify the database path depending on whether the database file is a SQLite file. For SQLite files (identified by '.sqlite' in their name), it adjusts the path by prefixing it with a specific directory path (database_path('dbs/')). For other types of databases, it simply returns the provided path or name as is.

  1. Default Connection
'default' => env('DB_CONNECTION', 'laravel'),

Sets the default database connection. If not specified in the environment file, it defaults to laravel.

  1. Connection Setup:

Each connection (e.g., 'main', 'laravel', 'misc') has parameters for read and write operations. These parameters include host, port, username, password, and unix_socket configurations.

  1. Connection Specifics:

Each connection (e.g., 'product', 'click_and_collect') has its unique setup and may use either mysql or singlestore based on specific conditions:

'product' => env('PRODUCT_DB_DRIVER') === 'singlestore' ? [
    'driver' => 'singlestore',
    // ...
] : [
    'read' => [
        // ...
    ],
    'write' => [
        // ...
    ],
    'sticky' => true,
    'driver' => env('PRODUCT_DB_DRIVER', env('DEFAULT_DB_DRIVER', 'mysql')),
    // ...
],

spiralroadrunner

  • Package Version in ECOM-API : "2.0"

In a Laravel application, spiral/roadrunner is a high-performance PHP application server that can be used as an alternative to traditional web servers like Apache or Nginx. It's designed to provide a more efficient way to handle PHP requests by managing concurrency and reducing overhead.

Installation

composer require spiral/roadrunner

superbalistlaravel-google-cloud-storage

  • Package Version in ECOM-API : "2.2"

Integrates Google Cloud Storage with Laravel, enabling you to use Google Cloud Storage as a file storage disk. Configure the disk in config/filesystems.php and set up credentials in your .env file.

Filesystem Configuration in ECOM

The filesystems.php file in Laravel configures the filesystem disks and symbolic links for file storage. Here’s a breakdown of the configuration options and disks available in the default setup.

  • Default Filesystem Disk
    The default key specifies the default filesystem disk that Laravel will use. This disk will be used for file operations unless otherwise specified.
     'default' => env('FILESYSTEM_DRIVER', 'local'),
    
    • FILESYSTEM_DRIVER: This environment variable determines the default filesystem disk. By default, it falls back to local.
  • Filesystem Disks
    In the ECOM Application there are multiple filesystem disks here.such as local, ftp, sftp, or s3. Each disk configuration is defined as an array.
    • Local DIsk : The local disk is used for local file storage within the application.
      'local' => [
      'driver' => 'local',
      'root' => storage_path('app'),
      ],
      
      • driver: Specifies the storage driver. Here it’s local for local file storage.
      • root: The root directory where files will be stored. Uses Laravel's storage_path helper.
    • Public Disk public disk is used for files that are accessible publicly via a URL.
         'public' => [
         'driver' => 'local',
         'root' => storage_path('app/public'),
         'url' => env('APP_URL').'/storage',
         'visibility' => 'public',
         ],
      
    • Google Cloud Storage Disks : Two Google Cloud Storage disks are configured, each with specific settings.
      1. Bank Holidays Disk
        'bank-holidays' => [
        'driver' => 'gcs',
        'project_id' => env('GCS_BANK_HOLIDAY_DATA_GOOGLE_CLOUD_PROJECT_ID', 'project-id'),
        'key_file' => env('GCS_BANK_HOLIDAY_DATA_GOOGLE_CLOUD_KEY_FILE', ''),
        'bucket' => env('GCS_BANK_HOLIDAY_DATA_GOOGLE_CLOUD_STORAGE_BUCKET', 'bucket-name'),
        'path_prefix' => env('GCS_BANK_HOLIDAY_DATA_PATH_PREFIX', ''),
         'visibility' => 'private',
        ],
        
      • driver: gcs for Google Cloud Storage.
      • project_id: Google Cloud Project ID.
      • key_file: Path to the JSON key file for authentication.
      • bucket: The name of the Google Cloud Storage bucket.
      • path_prefix: Optional path prefix within the bucket.
      • visibility: Set to private to restrict access.
      1. Trade Credit Disk
         'trade-credit' => [
         'customer-documents' => [
           'driver' => 'gcs',
           'project_id' => env('TRADE_CREDIT_GOOGLE_CLOUD_PROJECT_ID', 'project-id'),
           'key_file' => env('TRADE_CREDIT_GOOGLE_CLOUD_KEY_FILE', ''),
           'bucket' => env('TRADE_CREDIT_GOOGLE_CLOUD_STORAGE_AUTO_EXPIRY_BUCKET', 'bucket-name'),
           'path_prefix' => env('TRADE_CREDIT_CUSTOMER_DOCUMENTS_PATH_PREFIX', ''),
           'visibility' => 'private',
            'signed_url' => [
            'timeout' => 5,
            'min_length' => 0,
            'max_length' => 10000000,
            ],
           'allowed_mime_types' => [
            'image/bmp',
            'image/png',
            'image/jpeg',
            'application/pdf',
            'application/vnd.oasis.opendocument.text',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
          ],
        ],
       ],
      
      1. S3 Disk : The s3 disk is used for storing files on Amazon S3.
         's3' => [
         'driver' => 's3',
         'key' => env('AWS_ACCESS_KEY_ID'),
         'secret' => env('AWS_SECRET_ACCESS_KEY'),
         'region' => env('AWS_DEFAULT_REGION'),
         'bucket' => env('AWS_BUCKET'),
         'url' => env('AWS_URL'),
         'endpoint' => env('AWS_ENDPOINT'),
         ],
        
    • Symbolic Links

    Symbolic links can be configured to link directories. For example, creating a symbolic link from public/storage to storage/app/public.
     'links' => [
      public_path('storage') => storage_path('app/public'),
      ],
    

toolstation

In the composer.json file, the dependencies listed with @dev indicate that you're using the development versions of these packages. This is typically done when you want to use the latest development code or if the packages are not yet stable.

They cover a wide range of functionalities, including authentication, catalog management, content handling, orders, payments, and more.

In Composer.json

"require": {
        "php": "^8.0",
        "toolstation/auth": "@dev",
        "toolstation/autoprinter": "@dev",
        "toolstation/carrier": "@dev",
        "toolstation/catalogue": "@dev",
        "toolstation/content": "@dev",
        "toolstation/contracts": "@dev",
        "toolstation/core": "@dev",
        "toolstation/couchdb": "@dev",
        // Other
}

Toolstation Package in Application This package provides various service providers, they are registered in config/app.php:

'providers' => [
    Toolstation\Auth\AuthServiceProvider::class,
    Toolstation\Autoprinter\AutoprinterServiceProvider::class,
    Toolstation\Carrier\CarrierServiceProvider::class,
    Toolstation\Trolleys\ServiceProvider::class,
    // Other Service Providers
    
     /*
         * Toolstation WHAM Module Service Provider
         * This service provider registers all the wham container bindings we need for this application
         */
        App\Providers\WhamServiceProvider::class,
],

Toolstation WHAM Module Service Providers.

/*
         * Toolstation WHAM Module Service Provider
         * This service provider registers all the wham container bindings we need for this application
         */
        App\Providers\WhamServiceProvider::class,

Repositories

"repositories": [
        {
            "type": "path",
            "url": "../wham/*"
        }
    ],
  • repositories: Defines additional package sources.
    • type: "path"`: This specifies that packages will be loaded from a local path.
    • url: "../wham/*"`: The path to the local directory containing packages. This allows you to use packages that are in development or not available in Packagist.

Usage:

class ProductController extends Controller
{
    /**
     * @var ProductService
     */
    private $productService;

    /**
     * ProductController constructor.
     *
     * @param ProductService $productService
     */
    public function __construct(ProductService $productService)
    {
        $this->productService = $productService;
    }
}

In this example, ProductService is injected into the controller via the constructor.

Important The Wham Services are registered in the app/provider/WhamServiceProvider.php

public function register()
    {
        // Override WHAM bindings
        $this->app->bind(\Toolstation\Contracts\Products\ProductService::class, \App\Services\ProductService::class);
        $this->app->bind(\Toolstation\Contracts\Orders\OrderService::class, \App\Services\OrderService::class);
        $this->app->bind(\Toolstation\Contracts\Customers\CustomerService::class, \App\Services\CustomerService::class);

        // Set up all the wham project bindings
        $this->app->bind(\Toolstation\Contracts\Orders\BundleConfigService::class, \Toolstation\Orders\Services\BundleConfigService::class);
        // Other Bindings....
        }

require-dev

"require-dev": {
        "barryvdh/laravel-debugbar": "^3.6",
        "beyondcode/laravel-query-detector": "^1.5",
        "brianium/paratest": "^6.2",
        "ddelnano/dredd-hooks-php": "^2.0",
        "facade/ignition": "^2.5",
        "fakerphp/faker": "^1.9.1",
        "friendsofphp/php-cs-fixer": "^3.0",
        "mockery/mockery": "^1.4.2",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.3.3",
        "timacdonald/log-fake": "^1.9",
        "toolstation/utilities": "@dev"
    },

The require-dev section lists the packages that are required only for development purposes. These packages are not needed in the production environment. Here's a breakdown of each package:

barryvdh/laravel-debugbar: "^3.6" Purpose: Provides a debug bar with detailed information about your Laravel application's performance and requests. Useful for debugging and development.

beyondcode/laravel-query-detector: "^1.5" Purpose: Detects N+1 query problems and inefficient queries in Laravel applications. Helps in identifying performance issues related to database queries.

brianium/paratest: "^6.2" Purpose: Runs PHPUnit tests in parallel, speeding up the testing process by utilizing multiple CPU cores.

ddelnano/dredd-hooks-php: "^2.0" Purpose: Provides hooks for Dredd, a tool for API testing based on API descriptions. This package integrates with PHP to allow Dredd to execute tests against your API.

facade/ignition: "^2.5" Purpose: Laravel’s default error page and debugging tool. Provides a detailed error page and error handling capabilities.

fakerphp/faker: "^1.9.1" Purpose: Generates fake data for testing and seeding your application. Useful for populating databases with dummy data.

friendsofphp/php-cs-fixer: "^3.0" Purpose: PHP Coding Standards Fixer helps to automatically fix coding standards issues in PHP code. Ensures consistency in coding style.

mockery/mockery: "^1.4.2" Purpose: A flexible mock object framework for PHP. Useful for creating mock objects in unit tests.

nunomaduro/collision: "^5.0" Purpose: A CLI error handler for Laravel that provides beautiful error messages and stack traces when your tests or artisan commands fail.

phpunit/phpunit: "^9.3.3" Purpose: The testing framework used for running unit tests in PHP. Essential for writing and executing tests.

timacdonald/log-fake: "^1.9" Purpose: Provides a fake logger for testing purposes. Useful for testing logging functionality without writing to actual logs.

toolstation/utilities: "@dev" Purpose: A custom development package from Toolstation, likely containing additional utility functions or classes needed for development. The @dev constraint indicates that it's a development version.

autoload

The autoload section defines how the application’s classes are loaded. This configuration uses PSR-4 autoloading standard.

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/"
    }
}

autoload-dev

The autoload-dev section is similar to autoload, but it’s used for development-specific classes.

"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
}

scripts

The scripts section defines custom Composer scripts that can be executed at various stages of the Composer lifecycle.

"scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ],
        // Other scripts.
}

GeoIP2

The GeoIP2 package provides GeoIP2 support for Laravel. It is a wrapper around the MaxMind GeoIP2 library. The GeoIP2 library provides IP-based geolocation services, allowing you to determine the location of website visitors based on their IP addresses.

Installing

composer require danielme85/laravel-geoip2
php artisan vendor:publish --provider="danielme85\Geoip2\Geoip2ServiceProvider"

Configuration

You can configure GeoIp in config/geoip.php.

Add your geoip licence to your env file:

GEOIP2_LICENSE=XXXXX

Usage

return [
    'geoip2' => [
        'downloadUrl' => 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz', //url db file download
        'tempFile' => 'app/GeoLite2-City.mmdb.gz', //temp download file name
        'dbName' => 'app/GeoLite2-City.mmdb', //Geoip DB filename
        'localhost' => '8.8.8.8' //when running on localhost (or for general testing) you can specify a fake ip address here.
    ]
];

Libphonenumber for php

The giggsey/libphonenumber-for-php package is a PHP library for parsing, formatting, and validating phone numbers. It provides functionality to work with phone numbers in various formats and regions.

Installation

composer require giggsey/libphonenumber-for-php

Usage

return [
    'libphonenumber' => [
        'defaultRegion' => 'US'
    ]
];

Google Cloud

The google/cloud package provides access to various Google Cloud services and APIs, allowing you to interact with Google Cloud resources programmatically. It is the official PHP API client for Google Cloud Platform.

Installation

composer require google/cloud

Usage

    return [
        'google' => [
            'storage' => [
                'driver' => 'gcs',
                'key_file' => env('GOOGLE_CLOUD_KEY_FILE', ''),
                'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'bucket-name'),
                'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', ''),
                'visibility' => 'public',
            ],
        ],
    ];

Configuration Breakdown in Ecom API

  • google/storage
    • driver: Specifies the storage driver. Here it’s gcs for Google Cloud Storage.
    • key_file: Path to the JSON key file for authentication.
    • bucket: The name of the Google Cloud Storage bucket.
    • path_prefix: Optional path prefix within the bucket.
    • visibility: Set to public to allow public access to files.

Guzzle Http

The guzzlehttp/guzzle package is a Guzzle HTTP library for PHP. It is used to send HTTP requests and receive HTTP responses. Guzzle simplifies the process of sending HTTP requests and handling responses, making it easier to interact with web services and APIs.

Installation

composer require guzzlehttp/guzzle

Configuration

return [
    'guzzle' => [
        'base_uri' => env('GATEWAY_BASE_URI', 'http://localhost:8080'),
    ],
];


Copyright © 2026