Modularize your laravel app in a package way.

Overview

Laravel Modular

Pustaka laravel untuk modularisasi kode secara rapi dan mudah di maintain.

Instalasi

$ composer require kodepandai/laravel-modular

Setelah terpasang, lakukan inisiasi pustaka modular

$ php artisan modular:install

Kemudian tambahkan konfigurasi berikut ini di composer.json

"extra": {
  // ...
  "merge-plugin": {
    "include": ["modules/*/composer.json"]
  }
  // ...
},

Penggunaan

Selayang Pandang

Laravel modular ini dibuat dengan konsep bahwa tiap modul dianggap sebagai sebuah pustaka tersendiri. Jadi struktur folder dan kondisinya sama seperti ketika kita membuat pustaka laravel.

Modul Baru

$ php artisan modular:make Sales

*Sales adalah nama modul

Bekerja dengan modular

Konsep modular pada umumnya adalah semua hal (routes, config, migrations, dsb) di muat di awal tanpa perlu konfigurasi. Tetapi di laravel modular ini, tiap hal yang ingin di muat, harus di konfigurasi manual di ServiceProvider tiap modul. Mengapa? agar yang dimuat adalah benar-benar apa yang ingin dimuat. Be mindful.

Modul Service Provider

Contoh modul service provider:

namespace Sales;

use Illuminate\Support\Facades\Route;
use KodePandai\Modular\Module;
use KodePandai\Modular\ModuleServiceProvider;

class SalesServiceProvider extends ModuleServiceProvider
{
    public function configureModule(Module $module): void
    {
        $module->name('Sales')
            ->hasConfigFile('sales')
            // -> dst...
            ->hasMigrationPath('database/migrations');
    }
}
Configs

Letakkan konfigurasi di folder <module root>/config, lalu registrasikan dengan:

$module->hasConfigFile('example-config');
// atau
$module->hasConfigFiles(['example-config-1', 'example-config-2']);
Views

Letakkan templat views di folder <module root>/resources/views, lalu registrasikan dengan:

$module->hasViews();
View Components

Letakkan komponen view di folder <module root>/src/Components, lalu registrasikan dengan:

$module->hasViewComponent('sales', \Sales\Components\header::class);
// lalu panggil di blade dengan <sales::header />, atau
$module->hasViewComponents('sales', [
  \Sales\Components\Header::class,
  \Sales\Components\Sidebar::class,
]);
// lalu panggil di blade dengan <sales::header /> atau <sales::sidebar />
Translations

Letakkan file terjemahan di folder <module root>/resources/lang, lalu registrasikan dengan:

$module->hasTranslations();
Migrations

Letakkan migrasi, factory dan seeder di folder <module root>/database, lalu registrasikan dengan:

$module->hasMigrationPath('database/migrations');
// atau
$module->hasMigrationPaths([
  'migrations/sales',
  'migrations/accounting',
]);
Routes

Letakkan file route di folder <module root>/routes, lalu registrasikan dengan:

$module->hasRoute('web');
// atau
$module->hasRoutes(['web', 'api']);
Commands

Letakkan perintah konsol artisan di folder <module root>/src/Commands, lalu registrasikan dengan:

$module->hasCommand(\Module\Commands\CheckVersion::class);
// atau
$module->hasCommands([
  \Module\Commands\CheckVersion::class,
  \Module\Commands\CheckServer::class,
]);
Helpers

Letakkan file helper di folder <module root>/src/helpers.php, lalu registrasikan dengan:

$module->hasHelper('src/helpers.php');
// atau
$module->hasHelpers([
  'src/Helpers/str.php', 
  'src/Helpers/array.php',
]);
Middlewares

Letakkan middleware di folder <module root>/src/Http/Middleware/, lalu registrasikan dengan:

$module->hasMiddleware('admin', \Module\Http\Middleware\OnlyAdminAllowed::class);
// atau
$module->hasMiddlewares([
  'admin' => \Module\Http\Middleware\OnlyAdminAllowed::class,
  'reviewer' => \Module\Http\Middleware\OnlyReviewerAllowed::class,
]);
Service Providers

Apabila ada provider lain dalam modul, letakkan di folder <module root>/src/Providers, lalu registrasikan dengan:

$module->hasServiceProvider(\Module\Providers\PaymentServiceProvider::class);
// atau
$module->hasServiceProviders([
  \Module\Providers\PaymentServiceProvider::class,
  \Module\Providers\EventServiceProvider::class,
]);

Pengembang

  • Untuk tes jalankan composer test
You might also like...
 Laravel Logable is a simple way to log http request in your Laravel application.
Laravel Logable is a simple way to log http request in your Laravel application.

Laravel Logable is a simple way to log http request in your Laravel application. Requirements php = 7.4 Laravel version = 6.0 Installation composer

A web app for detecting backend technologies used in a web app, Based on wappalyzer node module

About Techdetector This a web fingerprinting application, it detects back end technologies of a given domain by using the node module wappalyzer. And

CV-Resumes-App is helped us to build resume .. you can help me to improve this app...

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Save Model is a Laravel package that allows you to save data in the database in a new way.

Save Model is a Laravel package that allows you to save data in the database in a new way. No need to worry about $guarded and $fillable properties in the model anymore. Just relax an use Save Model package.

A Laravel package to manage versions of endpoints in an elegant way

API version control A Laravel package to manage versions of endpoints in an elegant way Two ways to manage the versions of your endpoints Option 1: Ve

A laravel package to handle model specific additional meta fields in an elegant way.

Laravel Meta Fields A php package for laravel framework to handle model meta data in a elegant way. Installation Require the package using composer: c

Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords.

Laravel Otpify 🔑 Introduction Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords. Install

Podcastwala - Your very own Podcast web app built with Laravel. Manage and listen to your favorite podcasts
Podcastwala - Your very own Podcast web app built with Laravel. Manage and listen to your favorite podcasts

Podcastwala Your very own Podcast web app built with Laravel 5. This web app enables you to manage RSS feeds for your favorite podcasts and listen to

An easy way to get vendor and package data from Packagist via API calls
An easy way to get vendor and package data from Packagist via API calls

Laravel Packagist Laravel Packagist (LaravelPackagist) is a package for Laravel 5 to interact with the packagist api quickly and easily. Table of cont

Owner
Kode Pandai
Kumpulan Kode Buatan Anak Indonesia
Kode Pandai
Laravel Breadcrumbs - An easy way to add breadcrumbs to your @Laravel app.

Introduction Breadcrumbs display a list of links indicating the position of the current page in the whole site hierarchy. For example, breadcrumbs lik

Alexandr Chernyaev 269 Dec 21, 2022
Kalibrant - a package that provides a simple way to manage your models settings

Introduction For your laravel 9.x applications, Kalibrant is a package that provides a simple way to manage your models settings. It is a simple way t

Starfolk 3 Jun 18, 2022
This package aims to help you standardize all your API responses in a simple and structured way.

Laravel API Response This package aims to help you standardize all your API responses in a simple and structured way. By default, the stucture of the

Kode Pandai 6 Dec 6, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
A simple blog app where a user can signup , login, like a post , delete a post , edit a post. The app is built using laravel , tailwind css and postgres

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nahom_zd 1 Mar 6, 2022
Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App.

OvalFi Laravel Package Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App. Installation You can in

Paul Adams 2 Sep 8, 2022
This package enables you to create and run a fully functioning WebSocket server in your Laravel app.

This package enables you to create and run a fully functioning WebSocket server in your Laravel app. It can optionally receive messages broadcast over ZeroMQ.

Asked.io 181 Oct 6, 2022
A package to backup your Laravel app

A modern backup solution for Laravel apps This Laravel package creates a backup of your application.

Spatie 5.1k Dec 30, 2022
Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications.

Laravel Boilerplate Project Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications. Table of Con

Labs64 848 Dec 28, 2022
Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

Label84 16 Nov 23, 2022