Installation
composer require achinon/toolset
Add the service provider to config/app.php:
'providers' => [
// ...
Achinon\Toolset\ToolsetServiceProvider::class,
],
First Use Case: Helper Functions
The package provides a Toolset facade for common utilities. Access it immediately:
use Achinon\Toolset\Facades\Toolset;
// Example: Generate a UUID
$uuid = Toolset::uuid();
Where to Look First
app/Toolset.php (auto-generated) for available methods.README.md for core features (e.g., Toolset::slug(), Toolset::randomString()).src/ToolsetServiceProvider.php to see registered bindings.String Manipulation
// Slugify a string
$slug = Toolset::slug('Hello World!');
// Random string generation
$token = Toolset::randomString(32);
Data Transformation
// Convert snake_case to camelCase
$camel = Toolset::snakeToCamel('user_name');
// Array flattening
$flat = Toolset::flatten(['a' => ['b' => 1]]);
File/Path Handling
// Get relative path
$relative = Toolset::relativePath('/var/www', '/var/www/project/file.txt');
// Ensure trailing slash
$path = Toolset::ensureTrailingSlash('/var/www');
Integration with Laravel
$this->app->extend('toolset', function ($toolset) {
$toolset->extend('customMethod', function () {
return 'Custom logic';
});
return $toolset;
});
Toolset::blade()->directive('uuid', function () {
return "<?php echo \\Achinon\\Toolset\\Toolset::uuid(); ?>";
});
Testing Use the facade in tests for consistent utility methods:
public function testSlugGeneration()
{
$this->assertEquals('hello-world', Toolset::slug('Hello World!'));
}
Namespace Collisions
str()), ensure no conflicts with Laravel’s Str helper.use Toolset as ToolsetUtils;
Undefined Methods
method_exists():
if (method_exists(Toolset::getFacadeRoot(), 'someMethod')) {
Toolset::someMethod();
}
Configuration Overrides
config/toolset.php), ensure defaults align with your project:
'default_locale' => 'en_US', // Override if needed
Inspect the Facade Root Dump the underlying class to explore methods:
dd(method_get_properties(new \Achinon\Toolset\Toolset()));
Check for Static Methods Some utilities might be static. Access them directly:
\Achinon\Toolset\Toolset::staticMethod();
Extension Points
$toolset->extend('myMethod', function () {
return 'Extended!';
});
php artisan vendor:publish --tag=toolset-config
Avoid Facade Calls in Loops: Cache results if methods are called repeatedly:
$cachedSlug = cache()->remember('slug_key', now()->addHours(1), function () {
return Toolset::slug($input);
});
Memory Usage: For large data transformations (e.g., flatten()), test with sample datasets first.
if (Toolset::respondsTo('unknownMethod')) {
// Safe to call
}
How can I help you explore Laravel packages today?