PHP code example of dandysi / laravel-monorepo

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

    

dandysi / laravel-monorepo example snippets



use Illuminate\Support\Facades\Route;

protected function configureRoutes()
{
    Route::middleware('api')
        ->prefix('api')
        ->group(__DIR__ . '/routes.php')
    ;
}

use Chores\Console\ExpireArticlesCommand;

protected function registerCommands(): array
{
    return [
        ExpireArticlesCommand::class
    ];
}

use Illuminate\Console\Scheduling\Schedule;

protected function registerSchedule(Schedule $schedule): void
{
    $schedule->command(ExpireArticlesCommand::class)->daily();
}

protected function registerEventListeners(): array
{
    return [
        ArticleCreated::class => [
            UpdateArticleCachListener::class
        ],    
        ArticleDeleted::class => [
            UpdateArticleCachListener::class
        ]
    ];
}

protected function registerEventSubscribers(): array
{
    return [
        UpdateArticleCacheSubscriber::class
    ];
}

protected function registerConfig(): array
{
    return [
        'chores' => 

// config/database.php
use Dandysi\Laravel\Monorepo\MonorepoProvider;

return [
    'connections' => MonorepoProvider::dbConnectionsConfig([
        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ]
    ])
];


// microservices/Chores/MonorepoPrvider.php

public static function dbConnectionsConfig(array $default): array
{
    $default['new_db'] => [
        // ...
    ];

    return $default;
}
bash
php artisan make:monorepo-provider Chores
bash
php artisan make:monorepo-provider Chores microservices/Chores
bash
php artisan make:monorepo-test-case Chores/Tests microservices/Chores/Tests Chores
bash
MONOREPO_PROVIDER=Chores\\MonorepoProvider php artisan chores:some_command
bash
MONOREPO_PROVIDER=Chores\\MonorepoProvider php artisan serve