splash/toolkit
Splash Toolkit is a Laravel/PHP utility package that bundles common helpers and tooling to speed up app development. It provides reusable components for everyday tasks, aiming to reduce boilerplate and keep projects consistent.
Installation
composer require splash/toolkit
Add the service provider to config/app.php under providers:
Splash\Toolkit\ToolkitServiceProvider::class,
First Use Case: Module Scaffolding Generate a basic module structure using Artisan:
php artisan splash:module MyModule
This creates:
app/Modules/MyModule/ (with Module.php, Providers/ModuleServiceProvider.php, etc.)module.json)Key Entry Points
register() in ModuleServiceProvider.boot() for late binding (e.g., view composers, middleware).php artisan vendor:publish --provider="Splash\Toolkit\ToolkitServiceProvider" --tag="config"
app/Modules/MyModule/
├── Config/ # Module-specific config
├── Database/ # Migrations, Seeders
├── Http/ # Controllers, Middleware, Routes
├── Resources/ # Views, Lang, Assets
├── Providers/ # Service Providers
└── module.json # Metadata (name, version, dependencies)
Route::module() in ModuleServiceProvider::boot():
Route::module('MyModule')->group(function () {
Route::get('/dashboard', 'DashboardController@index');
});
module.json:
{
"name": "MyModule",
"dependencies": {
"splash/auth": "^2.0",
"splash/ui": "^1.0"
}
}
Toolkit::module():
$authModule = Toolkit::module('auth');
ModuleServiceProvider:
$this->app->bind('MyModule\Contracts\MyService', function ($app) {
return new MyService($app->make('AnotherService'));
});
Toolkit::make():
$service = Toolkit::make('MyModule\Contracts\MyService');
php artisan splash:publish MyModule --assets
{{ splash_asset('MyModule::css/style.css') }}
{{ splash_script('MyModule::js/app.js') }}
php artisan splash:migrate MyModule
php artisan splash:migrate:rollback MyModule
Toolkit::module('MyModule')->listen('event.name', function ($payload) {
// Handle event
});
Toolkit::module('MyModule')->dispatch('event.name', ['key' => 'value']);
$module = Toolkit::module('MyModule');
$module->setEnvironment('testing'); // Mock services, DB, etc.
splash_asset() by extending Mix:
mix.setPublicPath('public/modules/MyModule');
Toolkit::module('broadcasting') for event broadcasting.Toolkit::module('auth')->extendUserModel().Resources/views/components.ToolkitCommand for module-specific tasks:
class MyModuleCommand extends ToolkitCommand
{
protected $signature = 'splash:my-module {action}';
protected $description = 'MyModule CLI tool';
public function handle()
{
$this->module = Toolkit::module('MyModule');
// Logic here
}
}
Circular Dependencies
Toolkit::module()->whenLoaded() or restructure dependencies.Asset Versioning
module.json:
"assets": {
"versioning": true
}
Service Provider Order
ModuleServiceProvider boots too early/late.Toolkit::module()->deferBoot() to delay bootstrapping.Database Conflicts
module.json:
"database": {
"prefix": "my_module_"
}
Route Caching
php artisan route:clear
module.json:
"routes": {
"cache": false
}
Module Loading Issues
storage/logs/laravel.log for ModuleNotFoundException.module.json is valid JSON and exists in the module root.Service Binding Failures
Toolkit::module()->getBindings() to inspect bindings.dd(Toolkit::module('MyModule')->getService('MyService'));
Asset Loading Failures
module.json:
"assets": {
"paths": {
"css": "Resources/assets/css",
"js": "Resources/assets/js"
}
}
php artisan splash:publish MyModule --assets --force
Event Dispatching
Toolkit::module('MyModule')->listen('*', function ($event) {
Log::debug("Event {$event->name} fired", $event->payload);
});
Environment-Specific Config
config/splash/modules.php:
'MyModule' => [
'debug' => env('APP_DEBUG', false),
'cache' => env('MY_MODULE_CACHE', 'file'),
],
Dynamic Module Paths
config/splash.php:
'modules_path' => app_path('CustomModules'),
Lazy Loading
module.json:
"lazy_load": true
Toolkit::module() to load only when first accessed.Custom Module Types
Splash\Toolkit\Contracts\Module for non-standard modules (e.g., CLI tools).Hooks System
Splash\Toolkit\Contracts\Hookable for module lifecycle hooks:
public function onInstall()
{
// Post-install logic
}
Plugin Architecture
Toolkit::module()->extend() to add functionality:
Toolkit::module('auth')->extend('user', function ($user) {
return new ExtendedUser($user);
});
Testing Utilities
$module = Mockery::mock('overload:Splash\Toolkit\Module');
Toolkit::shouldReceive('module')->andReturn($module);
API Integration
Toolkit::module()->api():
Toolkit::module('MyModule')->api()->get('/data', function () {
return ['key' => 'value'];
});
How can I help you explore Laravel packages today?