PHP code example of khaleelibrahim / laravel-modular

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

    

khaleelibrahim / laravel-modular example snippets


return [
    'namespace' => env('MODULAR_NAMESPACE', 'App\\Modules'),
    'path' => env('MODULAR_PATH', app_path('Modules')),
    'auto_register_providers' => env('MODULAR_AUTO_REGISTER', true),
];

abstract class BaseRepository
{
    protected int $cacheTTL = 600; // override per-repository if needed

    abstract protected function tag(): string;

    protected function cacheKey(string $suffix): string { /* scopes by app('tenant') automatically */ }
    protected function remember(string $key, Closure $callback) { /* ... */ }
    protected function flush(): void { /* ... */ }
}

use App\Modules\Blog\Controllers\PostController;
use Illuminate\Support\Facades\Route;

Route::prefix('v1/posts')
    ->middleware(['api', 'auth:sanctum'])
    ->group(function () {
        Route::get('/', [PostController::class, 'index']);
        Route::post('/', [PostController::class, 'store']);
        Route::get('/{id}', [PostController::class, 'show']);
        Route::put('/{id}', [PostController::class, 'update']);
        Route::delete('/{id}', [PostController::class, 'destroy']);
    });
bash
php artisan vendor:publish --tag=modular-config
php artisan vendor:publish --tag=modular-stubs
bash
php artisan make:module Blog
php artisan make:module-model Blog Post
php artisan make:module-repository Blog Post
php artisan make:module-service Blog Post
php artisan make:module-controller Blog Post
php artisan make:module-request Blog Post
php artisan make:module-resource Blog Post