PHP code example of drivkraft / interlock

1. Go to this page and download the library: Download drivkraft/interlock 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/ */

    

drivkraft / interlock example snippets


// config/interlock.php
return [
    'path' => base_path('modules'),      // keep the merge plugin's ',             // root namespace for new modules
    'tests_base' => 'Tests\TestCase',    // exposed to custom stubs
    'stubs' => null,                     // custom make:module stubs, null = package stubs

    // Folder per generator, relative to `source`
    'directories' => [
        'model' => 'Models',
        'enum' => 'Enums',
        'interface' => 'Contracts',
        'trait' => 'Concerns',
        'scope' => 'Models/Scopes',
        'data' => 'Data',
        'action' => 'Actions',
    ],

    // Group attributes per route file name; unlisted files load ungrouped
    'routes' => [
        'web' => ['middleware' => ['web']],
        'api' => ['middleware' => ['api'], 'prefix' => 'api'],
    ],

    // Used only when Livewire is installed
    'livewire' => [
        'components' => 'resources/views/components',
        'namespaces' => [
            'pages' => 'resources/views/pages',
            'layouts' => 'resources/views/layouts',
        ],
    ],

    // Each discovery type can be turned off
    'discover' => [
        'providers' => true, 'routes' => true, 'views' => true, 'translations' => true,
        'migrations' => true, 'components' => true, 'livewire' => true, 'commands' => true,
        'events' => true, 'factories' => true,
    ],

    'cache' => base_path('bootstrap/cache/interlock.php'),
];

'routes' => [
    'web' => ['middleware' => ['web']],
    'api' => ['middleware' => ['api'], 'prefix' => 'api'],
    'tenant' => ['middleware' => ['web', 'auth', 'tenant'], 'prefix' => 'app'],
],

'stubs' => [
    'composer.json' => base_path('stubs/modules/composer.json.stub'),
    'StubSourceDirectory/Providers/StubClassNamePrefixServiceProvider.php' => base_path('stubs/modules/provider.stub'),
    'README.md' => base_path('stubs/modules/readme.stub'),
],

use Drivkraft\Interlock\Facades\Interlock;

Interlock::modules();                              // Collection<string, Module>
Interlock::module('billing')?->namespace;          // 'Module\Billing\'
Interlock::moduleForClass(Invoice::class)?->name;  // 'billing'
Interlock::moduleForPath(__FILE__);
bash
php artisan vendor:publish --tag="interlock-config"
bash
php artisan make:module billing
php artisan module:model Invoice --module=billing -mf
php artisan module:controller InvoiceController --module=billing
php artisan migrate
text
modules/billing/
├── composer.json                   Module\Billing\ => src/
├── src/
│   ├── Http/Controllers/InvoiceController.php
│   ├── Models/Invoice.php
│   └── Providers/BillingServiceProvider.php
├── routes/web.php                  loaded in the web group
├── resources/views/                view('billing::...')
├── lang/                           __('billing::...')
├── database/{migrations,factories,seeders}/
└── tests/