kuroragi / general-helper
General helpers, blameable trait, activity log service, and macros for Laravel ERP applications.
Requires
- php: ^8.1
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.5|^11.0
Suggests
- barryvdh/laravel-dompdf: Required for PDF generation features (^2.0|^3.0|^4.0)
- spatie/laravel-permission: Required for role/permission-based authorization exception handling (^5.5|^6.0|^7.0)
This package is auto-updated.
Last update: 2026-04-02 09:48:21 UTC
README
A Laravel utility package for ERP and general applications provides a Blameable trait, activity logging, Blueprint/Eloquent macros, authorization exception handling, and common helper functions for Bahasa Indonesia formatting.
Compatible with Laravel 10, 11, and 12.
Requirements
- PHP ^8.1
- Laravel ^10.0 | ^11.0 | ^12.0
Optional Dependencies
spatie/laravel-permissionfor role/permission-based authorization exception handlingbarryvdh/laravel-dompdffor PDF generation features
Installation
composer require kuroragi/general-helper
The service provider is auto-discovered via Laravel package auto-discovery.
Publish Config
php artisan vendor:publish --tag=config --provider="Kuroragi\GeneralHelper\Providers\GeneralHelperServiceProvider"
Configuration
// config/kuroragi.php return [ 'config_version' => 2, 'activity_log_path' => storage_path('logs/activity'), 'activity_log_file_prefix' => 'activity-', 'roll_day' => 'monday', 'roll_time' => '01:00', 'default_reader_limit' => 50, 'auth_model' => null, 'authorization_exception' => [ 'enabled' => true, 'redirect_type' => 'route', 'redirect_to' => 'dashboard', 'session_key' => 'no_access', 'message' => 'Kamu tidak memiliki hak akses ke halaman tersebut.', 'json_response' => true, ], ];
config_versioncompare your local value with the package source after upgrading. If lower, re-publish to get new config keys.
Features
1. Blameable Trait
Auto-fills created_by, updated_by, deleted_by on Eloquent model events.
Migration:
Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->timestamps(); $table->softDeletes(); $table->blameable(); // adds all three columns with FK to users });
Model:
use Kuroragi\GeneralHelper\Traits\Blameable; class Post extends Model { use Blameable; }
Relations are available automatically:
$post->createdBy; // User $post->updatedBy; // User $post->deletedBy; // User
2. Blueprint Migration Macros
$table->blameable(); // created_by, updated_by, deleted_by (FK to 'users') $table->blameable('admins'); // FK to custom table $table->blameable(null, false); // no FK constraint $table->createdBy(); $table->updatedBy(); $table->deletedBy(); $table->dropBlameable('posts'); // drop columns + FK
3. Eloquent Query Macros
Post::createdBy($userId)->get(); Post::updatedBy($userId)->get(); Post::deletedBy($userId)->get(); Post::createdBy()->get(); // defaults to Auth::id()
4. Activity Logger
$logger = app('kuroragi.activity'); $logger->log([ 'level' => 'info', 'category' => 'purchase_order', 'message' => 'PO #001 created', 'meta' => ['po_id' => 1, 'total' => 500000], ]); $logger->transaction('Invoice finalized', ['invoice_id' => 55]);
Daily log files stored at storage/logs/activity/activity-YYYY-MM-DD.log. Each line is a JSON object.
5. Activity Log Reader
$reader = new \Kuroragi\GeneralHelper\ActivityLog\ActivityLogReader(storage_path('logs/activity')); $reader->read(); // last 50 entries $reader->read(100); // last 100 entries $reader->read(null, 'invoice'); // keyword filter $reader->read(null, null, 'purchase_order'); // category filter $reader->read(null, null, null, '2026-04-01', '2026-04-02'); // date range
Also reads from .zip archives generated by the roll command.
6. Weekly Log Rotation
Logs are auto-compressed to a weekly .zip archive every Monday at 01:00 (configurable).
php artisan kuroragi:roll-activity-logs
Ensure the Laravel Scheduler is running:
* * * * * cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1
7. Authorization Exception Handler
Handles AuthorizationException (403) with configurable redirect and flash message instead of a raw error page.
Blade:
@if(session('no_access')) <div class="alert alert-danger">{{ session('no_access') }}</div> @endif
redirect_type |
Behaviour |
|---|---|
route |
redirect()->route($redirect_to) |
url |
redirect($redirect_to) |
back |
redirect()->back() |
home |
redirect('/') |
Returns a JSON 403 response for AJAX/Livewire requests when json_response is true.
8. General Helper Functions
use Kuroragi\GeneralHelper\GeneralHelper; GeneralHelper::getSlug('Halo Dunia!'); // "halo-dunia" GeneralHelper::convertDateToIndo('2026-04-02'); // "2 April 2026 00:00:00" GeneralHelper::convertDateToIndoShort('2026-04-02'); // "02 Apr 2026" GeneralHelper::getTerbilang(12500000); // "dua belas juta lima ratus ribu" GeneralHelper::getIndoDate('2026-04-02'); // "Kamis, 2 April 2026" GeneralHelper::getIndoDateTerbilang('2026-04-02'); // "Kamis, 2 April 2026 dua"
Testing
composer test
Package Structure
kuroragi-general-helper/
composer.json
phpunit.xml
CHANGELOG.md
config/
kuroragi.php
src/
GeneralHelper.php
ActivityLog/
ActivityLogger.php
ActivityLogReader.php
Commands/RollActivityLogs.php
Macros/
BlueprintMacros.php
EloquentMacros.php
Providers/
GeneralHelperServiceProvider.php
Traits/
Blameable.php
tests/
TestCase.php
Unit/
GeneralHelperTest.php
ActivityLoggerTest.php
ActivityLogReaderTest.php
MacrosTest.php
Changelog
See CHANGELOG.md for full history.
License
The MIT License (MIT).